Whenever I add a javascript or css file to my asp.net core project and I execute dotnet run in my bash terminal, I get the following error:
/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft
.NET.Sdk.DefaultItems.targets(188,5): error : 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.
For more information, see https://aka.ms/sdkimplicititems. The
duplicate items were: ‘wwwroot/css/BasicQuotation.css’;
‘wwwroot/js/BasicQuotation.js’
[/mnt/c/Dev/myproject/MyProject/MyProject.csproj]The build failed. Please fix the build errors and run again.
I can fix this by removing the ItemGroup from my csproj file, but I don’t think that’s very productive.
This happens in the default Visual Studio 2017 ASP.NET Core Web Application (.NET Core) template. I add the files to my project by right clicking the wwwroot > js folder and then select Add > New Item > JavaScript File
This is my .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
<PropertyGroup>
<UserSecretsId>aspnet-MyProject-7e1906d8-5dbd-469a-b237-d7a563081253</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<Compile Remove="wwwrootlibjquery-validation**" />
<Content Remove="wwwrootlibjquery-validation**" />
<EmbeddedResource Remove="wwwrootlibjquery-validation**" />
<None Remove="wwwrootlibjquery-validation**" />
</ItemGroup>
<ItemGroup>
<Content Include="wwwrootcssBasicQuotation.css" />
<Content Include="wwwrootjsBasicQuotation.js" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="DataCommands" />
<Folder Include="DataQueries" />
<Folder Include="wwwrootimages" />
</ItemGroup>
</Project>
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
1. Click 'Show All Files' in Solution Explorer 2. Right-click over 'wwwroot' select 'Exclude From Project' 3. Right-click over 'wwwroot' select 'Include in Project'
Method 2
So I ran into this same issue. I didn’t want to turn off DefaultCompileItems because I knew that wouldn’t “fix” the problem. So I unloaded my project and opened the .csproj file in text mode in Visual Studio and saw this.
<ItemGroup>
<Content Include="wwwrootcsscustom-bootstrap-navbar.css" />
<Content Include="wwwrootimagesfriends-eatingimage1.jpg" />
<Content Include="wwwrootimagesfriends-eatingimage2.jpg" />
<Content Include="wwwrootimagesfriends-eatingimage3.jpg" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwrootimagesfriends-eating" />
</ItemGroup>
When I commented out the first ItemGroup block, it worked. What I assume is happening is that the project is adding the entire imagesfriends-eating folder and then adding each individual image, causing a duplication.
As far as the custom css and js, the project automatically adds wwwrootcss and wwwrootjs so if you have an individual file added (like wwwrootcsscustom-bootstrap-navbar.css) it’ll count as a duplicate.
Method 3
This worked in my case:
<PropertyGroup>
...
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>
Method 4
It happend when I upgrade my project from .NET Core 1.X to 2.0 just now. Here is my solution.
- Open xxx.csproj, or right click project
- Unload Project
- Edit xxx.csproj.
Then remove ItemGroup items start with <Content Include = "wwwrootxxxxx"
Method 5
As link says, you can disable this behavior (auto-include) and include all content explicitly by adding this into your csproj file:
<PropertyGroup>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>
Method 6
My issues was close but not the exact same. My error was this:
C:Program Filesdotnetsdk2.0.0-preview2-006497SdksMicrosoft.NET.SdkbuildMicrosoft.NET.Sdk.DefaultItems.targets(285,5): error : 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. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: ‘wwwrootjsKOBindings.js’; ‘wwwrootjsKOPleaseWait.js’; ‘wwwrootjsProjectTimeAdd.js’; ‘wwwrootjsTimeAdminInvoice.js’; ‘wwwrootjsTimeAdminPayPeriodTotals.js’ [C:Avantia ProjectsTime Cardavantia-timesheetSolutionAlmanacAlmanac.csproj]
If I did this:
<EnableDefaultContentItems>false</EnableDefaultContentItems>
It would not compile as all of the sudden Areas would not be recognized.
My solution, seems odd, but the message is telling me so, there were duplicate files:
The duplicate items were: ‘wwwrootjsKOBindings.js’; ‘wwwrootjsKOPleaseWait.js’; ‘wwwrootjsProjectTimeAdd.js’; ‘wwwrootjsTimeAdminInvoice.js’; ‘wwwrootjsTimeAdminPayPeriodTotals.js’
Looking at my .csproj file:
<ItemGroup> <Content Include="pdf.js" /> <Content Include="wwwrootjspackage.json" /> <Content Include="wwwrootjspdf.js" /> <Content Include="wwwrootjsKOBindings.js" /> <Content Include="wwwrootjsKOPleaseWait.js" /> <Content Include="wwwrootjsProjectTimeAdd.js" /> <Content Include="wwwrootjsTimeAdminInvoice.js" /> <Content Include="wwwrootjsTimeAdminPayPeriodTotals.js" /> </ItemGroup>
This was the ONLY location within the entire project where these files were references (aside from where they were loaded.) So the phrase duplicate does not make any sense to me. However, commenting those files out as such, took care of my problem:
<ItemGroup>
<Content Include="pdf.js" />
<Content Include="wwwrootjspackage.json" />
<Content Include="wwwrootjspdf.js" />
<!--
<Content Include="wwwrootjsKOBindings.js" />
<Content Include="wwwrootjsKOPleaseWait.js" />
<Content Include="wwwrootjsProjectTimeAdd.js" />
<Content Include="wwwrootjsTimeAdminInvoice.js" />
<Content Include="wwwrootjsTimeAdminPayPeriodTotals.js" />
-->
</ItemGroup>
I assume this has something to do with the 2.0.0-preview2-006497 that I recently installed.
Also, this link mentions talks about globs. But does not tell me where that is. It talks about SDKs and such. Yet the answer was my custom .js files. That link needs to be updated or expanded on IMHO. Hope this helps someone.
Method 7
In my case, I solved this by deleting all files from the wwwroot-Directory in VS.
Unload and reload the Project.
Copy all files back in with VS.
Done
Method 8
Actually, Asp.net core automatically include content from wwwrootcss , wwwrootjs and wwwrootlib location, so despite this if your csproj file explicitly include content from those directories then those content will be duplicated so removing content from you csproj file is the better way to get rid of this error. So remove below content-
<ItemGroup>
<Compile Remove="wwwrootlibjquery-validation**" />
<Content Remove="wwwrootlibjquery-validation**" />
<EmbeddedResource Remove="wwwrootlibjquery-validation**" />
<None Remove="wwwrootlibjquery-validation**" />
</ItemGroup>
<ItemGroup>
<Content Include="wwwrootcssBasicQuotation.css" />
<Content Include="wwwrootjsBasicQuotation.js" />
</ItemGroup>
Method 9
.NET Core Projects
If you are in a class library, probably you’ll need to remove all Compile/Content elements from your csproj as those are included automatically.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<!-- NEEDED -->
<ItemGroup>
<ProjectReference />
<ProjectReference />
</ItemGroup>
<!-- NOT NEEDED -->
<ItemGroup>
<Compile Include="ModelsExampleClass.cs" />
<Content ... />
</ItemGroup>
</Project>
Method 10
Not that I can see it in your example above, to help other SO searchers..
You can also get this error when you have the same file listed twice in <Content Include="xxx" /> elements in your csproj file.
Remove the duplicate and rebuild.
Method 11
Under Visual Studio 2017 15.3, with .NET Core 2.0,
EnableDefaultCompileItems did not work for me.
I needed to add this to my .csproj
<PropertyGroup>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>
Method 12
My case I is disable both below default items.
<EnableDefaultContentItems>false</EnableDefaultContentItems> <EnableDefaultItems>false</EnableDefaultItems>
Method 13
I found a different proper solution.
- Right click on your mvc project and click Edit csproj.
- If you are adding files under wwwroot, just move them to a folder under wwwroot, let’s say it “theme”
And delete all content tags in csproj file if their exists, an example;
<Content Include="wwwrootthemefavicon.ico" /> <Content Include="wwwrootthemefontscyrillic-ext400.woff2" /> <Content Include="wwwrootthemefontscyrillic-ext700.woff2" />
And only add this;
<ItemGroup>
<Folder Include="wwwroottheme" />
</ItemGroup>
So, csproj file should be look like this;
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroottheme" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
...
With that way, I think you are adding all files under theme folder. So not include them one by one which occours some erros.
Method 14
Excluding and Including back the folders that have duplicates error worked for me! Hope this helps someone else!
Method 15
I think what disabling “EnableDefaultContentItems” isn’t the best option.
Manual cs-Proj file editing also isn’t the good idea at all.
So for our build server pipeline, we wrote very small tool what will remove all duplicated entries automatically:
dotnet-csproj-cleaner
We run it under Docker as the first build step in our continuous integration pipeline.
Method 16
I had the same problem with only a file, and all others were working (all my templates were stored directly in wwwroot/content). The project was not created by me so I don’t know many details.
The problem was fixed by renaming back and forth the file with the issue:
MyTemplate.html — renamed –> MyTemplate2.html — renamed –> MyTemplate.html
Note: At the first rename I got an error with something along the lines of “content configuration not found“, but the second rename worked without issues.
After this I was able to compile the project successfully.
Method 17
I’m just getting started and I had this error when I tried copying a wwwroot folder from a Web Application template to a project created with an API template. removing bootstrap solved it for me, which is fine because I just need jquery.
Method 18
So what worked for me was clicking on the file in question in the Solution Explorer and choosing “Exclude from Project”. Then re-add it back using “Include in Project”.
Method 19
All of the answers that were written before me did not resolve the ‘Duplicate’ errors for me, even though I had taken the due diligence to ensure their recommended procedures were followed.
For me, the ‘Duplicate content’ issue occurred when I tried to upgrade my WinUI 3 Application’s SDK from Windows App SDK 0.8 to 1.0 in the Nuget Package Manager. When I did this, my project began to produce this error on every compile, and I tried to do the Exclude/Include methods that other suggested, but to no avail.
It took me about eight hours to find the culprit, which was a reference to another WinUI library project that I still had on Windows App SDK 0.8. Once I upgraded the other WinUI library project to SDK 1.0, this error went away.
Leaving this answer here in case it helps anyone else.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0