Duplicate 'PackageReference' items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior

Viewed 2391

I am using Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.3.0 Preview 1.1.

enter image description here

Error

Severity    Code    Description Project File    Line    Suppression State
Error   NU1504  Duplicate 'PackageReference' items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior. The duplicate 'PackageReference' items are: StyleCop.Analyzers 1.1.118, StyleCop.Analyzers 1.1.118; Roslynator.Analyzers 3.2.2, Roslynator.Analyzers 3.2.2.   Shared.DTOs C:\Users\donhu\source\repos\FSH\src\Shared\Shared.DTOs\Shared.DTOs.csproj   1   

enter image description here

Error restoring packages

enter image description here

How to fix it?

1 Answers

Temporary solution: add <NoWarn>$(NoWarn);NU1504;NU1505;NU1701</NoWarn> , for example

Old

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <RootNamespace>FSHTemp.Application</RootNamespace>
    <AssemblyName>FSHTemp.Application</AssemblyName>
  </PropertyGroup>
...

new

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <RootNamespace>FSHTemp.Application</RootNamespace>
    <AssemblyName>FSHTemp.Application</AssemblyName>
      <NoWarn>$(NoWarn);NU1504;NU1505;NU1701</NoWarn>
  </PropertyGroup>

result: restore Nuget package success now

enter image description here

Long-term solution: Update to new version of Visual Studio 2022 (Stability and.or Preview update channels)

Related: https://github.com/dotnet/sdk/issues/24747

See more https://github.com/unoplatform/uno.todo/commit/6e442d9b1adb8f990139969413344b135714ed93

Related