sdk: NU1505: Duplicate 'PackageDownload' items warning is raised when the SDK uses PackageDownload to get packages.
Describe the bug
Recently NuGet added warnings for duplicate PackageReference/PackageDownload/PackageVersion items. Duplicate items could lead to an unpredictable behavior. You can learn about the motivation more in https://github.com/NuGet/Home/issues/9864. https://github.com/NuGet/Home/blob/dev/proposed/2022/duplicate-nuget-item-error-handling.md
NuGet added this in 6.0.400, so customers will start seeing this very soon.
To Reproduce
Originally filled in https://github.com/NuGet/Home/issues/11720.
- Use latest SDK with NuGet version 6.3.0 or higher. Might not be 100% inserted today.
- Create a .NET Core Console App, netcoreapp3.1. project with PackageReference package installed.
- Run “dotnet restore” in Developer Command Prompt for VS 2022 Preview
- The warning “warning NU1505: Duplicate ‘PackageDownload’ items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior.” occurs as below screenshot.
This was was discovered by the NuGet test team, @v-luzh Can you please post the csproj in question?

Why is this important?
NuGet will raise a warning when it sees duplicate items, and warning as errors could cause failures for customers.
Exceptions (if any)
Further technical details
- Include the output of
dotnet --info - The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version Latest main version of NuGet tooling will have this.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 33 (20 by maintainers)
Commits related to this issue
- Disable NU1505 warning until https://github.com/dotnet/sdk/issues/24747 is fixed. — committed to Tanya-Solyanik/winforms by Tanya-Solyanik 2 years ago
- Disable NU1505 warning until https://github.com/dotnet/sdk/issues/24747 is fixed. — committed to Tanya-Solyanik/winforms by Tanya-Solyanik 2 years ago
- Disable NU1505 warning until https://github.com/dotnet/sdk/issues/24747 is fixed. (#7024) — committed to dotnet/winforms by Tanya-Solyanik 2 years ago
- fix: Setting duplicate package reference/download to no warn (see https://github.com/dotnet/sdk/issues/24747) — committed to unoplatform/uno.todo by nickrandolph 2 years ago
- Fix issue building release mode tests locally See https://devblogs.microsoft.com/nuget/announcing-nuget-6-3-transitive-dependencies-floating-versions-and-re-enabling-signed-package-verification/#new-... — committed to michael-hawker/UWPCommunityToolkit by michael-hawker 2 years ago
- Fix issue building release mode tests locally See https://devblogs.microsoft.com/nuget/announcing-nuget-6-3-transitive-dependencies-floating-versions-and-re-enabling-signed-package-verification/#new-... — committed to michael-hawker/UWPCommunityToolkit by michael-hawker 2 years ago
- Fix issue building release mode tests locally See https://devblogs.microsoft.com/nuget/announcing-nuget-6-3-transitive-dependencies-floating-versions-and-re-enabling-signed-package-verification/#new-... — committed to michael-hawker/UWPCommunityToolkit by michael-hawker 2 years ago
It’d be nice if this error message actually pointed to the file/source locations of the project/props/target files that are including these references. I hit this issue with the new warnings in our project, but I’m just referencing the SDK and such, so no idea where the extra package reference is coming from. Changed the PackageReference from
IncludetoUpdatefor now to get around it… 🤷♂️Hey folks, we have a good idea what happened and what the path forward is now.
Cause
NuGet in VS is independent of the NuGet shipped with the SDK. The NuGet in VS has gotten ahead of the SDK, and it includes the additional validation for duplicate PackageDownloads and PackageReferences. As a result, when the NuGet in VS interacts with a project that uses an SDK that contains the PackageDownload duplication bug, these errors appear for users.
Mitigation
All of these duplicate checks are guarded by an MSBuild condition. If you set
DisableCheckingDuplicateNuGetItemstotruein your project files, the error should go away. You can also set the error codes toNoWarnlike so:<NoWarn>$(NoWarn);NU1505</NoWarn>. Note that since the SDK has had this bug lying latent for a while, simply moving to an older SDK version will not remove the issue. Theoretically you could also move to preview releases of either the 6.0.400 or 7.0.100 SDKs and the issue would resolve itself as well, since the SDK was fixed on both of those branches.Resolution
The SDK will ship version 6.0.400 in VS 17.3, so it was just a matter of time until we did an insertion to that preview. We will accelerate our timeline and do the insertion early next week (after dotnet/installer#13827 merges). That will unblock the internal dogfood previews of 17.3 for internal Microsoft users. For the broader public, this will not be fixed until 17.3 Preview 2 is released, which should be roughly a month from now.
I’m not sure on the urgency for this, but for what it’s worth it cost me a lot of time today and for others that pinged me as well. A lot of builds have warnings as errors deeply embedded in there and we’re all hacking at this passing in overrides for the properties to get by the current issue locally but for tomorrow I think it’s easier for me to uninstall the preview completely. I haven’t had to revert from a preview build in over a year now so this one is pretty serious IMO. I hope it makes a new preview build quickly for others hitting the issue - I think it warrants faster than a normal cadence from the number of reports I’m seeing.
@julealgon
The NU1504, NU1505 and NU1506 warnings were added in Visual Studio 17.3, NuGet.exe 6.3 and .NET SDK 6.0.400. All those tooling versions contain the same NuGet bits.
That shouldn’t be the case as the check is running as part of a target that’s run for each framework, so the conditions will be evaluated.
I can’t really say why you’re seeing the intermittent behavior, but if you are seeing issues with things that aren’t coming from the SDK (such as the NU1505 warnings for packages that are added by the SDK), I’d recommend filling a new issue.
You can file issues with questions about NU1504 in the NuGet/Home repo.
Hello. Still having the problem for me using VS 2022 Pro 17.3.0 x64 Fr (up to date) : “Duplicate ‘PackageDownload’ items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior. The duplicate ‘PackageDownload’ items are: Microsoft.NETCore.App.Ref [5.0.0], Microsoft.NETCore.App.Ref [3.1.0], Microsoft.NETCore.App.Ref [3.0.0]; Microsoft.WindowsDesktop.App.Ref [5.0.0], Microsoft.WindowsDesktop.App.Ref [5.0.0], Microsoft.WindowsDesktop.App.Ref [5.0.0], Microsoft.WindowsDesktop.App.Ref [3.1.0], Microsoft.WindowsDesktop.App.Ref [3.1.0], Microsoft.WindowsDesktop.App.Ref [3.1.0], Microsoft.WindowsDesktop.App.Ref [3.0.0], Microsoft.WindowsDesktop.App.Ref [3.0.0], Microsoft.WindowsDesktop.App.Ref [3.0.0]; Microsoft.AspNetCore.App.Ref [5.0.0], Microsoft.AspNetCore.App.Ref [3.1.10], Microsoft.AspNetCore.App.Ref [3.0.1]. Nolme.Core6 C:\Users[…]\Nolme.Core6.csproj”
Installed applications :
The project is attached. I found no mention of these packages 😦
Nolme.Core6.zip
@nkolev92 The repro project: Netcoreapp.zip
@baronfel I just hit what appears to be an invalid case for this warning. I have some packages conditionally added in my
Directory.Build.propsfile, but those are now being detected as duplicates even though the condition for the inclusion is false in the offending project.Here is an example:
Directory.Build.props(slightly simplified version of my real one)MyProject.Which.Is.Not.A.UnitTest.Project.csprojError:
It appears that the check is blindly looking at the presence of
PackageReferenceelements, ignoring whether or not they are conditionally added.I added the above code to
Directory.Build.propsas a means to share common setup across dozens of unit testing projects, but I have a couple of “testing libraries” that are not considered “unit test projects”, but still rely on some of the same packages that unit test projects do.This was working fine until I updated Visual Studio to latest versions (I’m using 17.3.1 right now). It is possible it was introduced in 17.3.0 but I actually don’t remember if I tried to build this project in between those 2 updates.
Note that my example here has nothing to do with SDK packages… its throwing for explicit libraries that I have in the projects.
I’ll add the ignore flag for now until this is fixed.
FAKE EDIT:
While I was posting this, I decided to try to create a “minimal repro” in a test solution here. Weirdly enough, it actually took a while to happen and I don’t know exactly what triggers it…
I had to keep adding new projects, fiddling with the variables in
Directory.Build.propsand suddenly it started throwing the warning. Then, I undid some of the stuff, built again, and it stopped raising the warning. When I got back to a previous version that was raising the warning before, it just kept working… I have no idea why it is intermittent like that.Hi @lonix1 - it looks like your warning isn’t raised by the SDK’s use of PackageDownloads (which was the cause of this issue). Your issue seems to be because you’re using different
PackageDownloadelements with different versions, and that’s not how CentralPackageManagement works (at least as far as I’m aware). CPVM requires your Directory.Package.Props to havePackageVersionitems, notPackageDownload, and your project files to havePackageReferenceitems, notPackageDownload. Can you try making those changes and see if your problem is resolved?For anyone who runs into the same issue – after upgrading the SDK version, the issue is resolved.
And if you are out there wondering where to put the <NOWARN> tag like I was
near the top of MyGreatApp.csproj
<PropertyGroup> <TargetFramework>net6.0</TargetFramework> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <NoWarn>NU1505</NoWarn>
</PropertyGroup>
great to find this page.
@NickCraver It’s not the ideal situation for sure! I’ll see what levers I can pull for a faster fix on the public release, though.