Share via


NuGet 警告 NU1505

案例 1

Duplicate 'PackageDownload' items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior. The duplicate 'PackageDownload' items are: X [1.0.0], X [2.0.0].

問題

有時候,新增 PackageDownload 專案時,您可能會多次加入特定套件的專案。

範例:

<ItemGroup>
  <PackageDownload Include="X" Version="[1.0.0]" />
</ItemGroup>
...
<!-- Somewhere else in the project file, or another MSBuild file-->
<ItemGroup>
  <PackageDownload Include="X" Version="[2.0.0]" />
</ItemGroup>

這可能會導致還原行為不一致。

解決方案

請參閱警告訊息中的建議,並執行下列其中一項動作:

  • 拿掉重複的專案
  • 使用專案 Update 而非專案 Include