NuGet Warning NU1506
Scenario 1
Duplicate 'PackageVersion' items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior. The duplicate 'PackageVersion' items are: X [1.0.0], X [2.0.0].
Issue
Sometimes when adding PackageVersion
items, you may end up adding an item for a particular package multiple times.
Example:
<ItemGroup>
<PackageVersion Include="X" Version="[1.0.0]" />
</ItemGroup>
...
<!-- Somewhere else in the project file, or another MSBuild file-->
<ItemGroup>
<PackageVersion Include="X" Version="[2.0.0]" />
</ItemGroup>
This can cause an inconsistent restore behavior.
Solution
Consult the recommendations in the warning message and do one of the following:
- Remove the duplicate items
- Use item
Update
instead of itemInclude