visual studio – How do I resolve, “Error NETSDK1022: Duplicate ‘Content’ items were included” error message?


I am attempting to migrate an ASP.NET Core 3.1 MVC project in Visual Studio 2022 to ASP.NET Core 6.0. The project builds and runs flawlessly on my development server but fails when uploaded to be built and deployed via our Azure DevOps CI/CD pipeline.

The following error message is being reported by Azure DevOps:

Error NETSDK1022: Duplicate ‘Content’ items were included. The .NET SDK includes ‘Content’ items from your project directory by default. You can either remove these items from your project file, or set the ‘EnableDefaultContentItems’ property to ‘false’ if you want to explicitly include them in your project file.

The duplicate items were: ‘C:\Users\VssAdministrator.nuget\packages\harfbuzzsharp.nativeassets.win32\7.3.0\buildTransitive et462….\runtimes\win-x86 ative\libHarfBuzzSharp.dll’; ‘C:\Users\VssAdministrator.nuget\packages\harfbuzzsharp.nativeassets.win32\7.3.0\buildTransitive et462….\runtimes\win-x64 ative\libHarfBuzzSharp.dll’; ‘C:\Users\VssAdministrator.nuget\packages\harfbuzzsharp.nativeassets.win32\7.3.0\buildTransitive et462….\runtimes\win-arm64 ative\libHarfBuzzSharp.dll’

If I am interpreting the error message correctly, there are two choices:

  • remove any references to the duplicate items from the project file; or
  • override the error message and manually manage the project file (not recommended)

According to the error message, the three duplicate items are actually transitive versions of the same file (libHarfBuzzSharp.dll), one for each of the three Windows variations (i.e. x86, x64 and arm64).

However, when I view the contents of the project file, I find no reference to the HalfBuzzSharp library which would allow me to remove any duplicates.

This is the contents of my project file:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <UserSecretsId>aspnet-**************-########-####-####-####-############</UserSecretsId>
    <WebProject_DirectoryAccessLevelKey>0</WebProject_DirectoryAccessLevelKey>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Extensions\**" />
    <Content Remove="Extensions\**" />
    <EmbeddedResource Remove="Extensions\**" />
    <None Remove="Extensions\**" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="certs\***\***********.key" />
    <Content Include="certs\***\***********.pem" />
    <Content Include="certs\***\***********.pfx" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.16.0" />
    <PackageReference Include="EPPlus" Version="7.7.3" />
    <PackageReference Include="GemBox.Spreadsheet" Version="49.0.1697" />
    <PackageReference Include="Magick.NET-Q16-AnyCPU" Version="14.8.2" />
    <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.3" />
    <PackageReference Include="Microsoft.Graph" Version="4.54.0" />
    <PackageReference Include="Microsoft.Identity.Web" Version="3.14.1" />
    <PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="3.14.1" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
    <PackageReference Include="SkiaSharp" Version="3.119.1" />
    <PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
    <PackageReference Include="System.Security.Cryptography.Xml" Version="8.0.0" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="6.0.0" />
    <PackageReference Include="System.Text.Json" Version="8.0.6" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="wwwroot\images\********\************\" />
  </ItemGroup>

</Project>

There are similar variations of this error message listed on other sites and, for the most part, the resolution seems to be to remove references from the project file. However, I do not appear to have that option available to me.

Have I missed something glaringly obvious?

Any assistance is greatly appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *