중복 된 '콘텐츠'항목이 포함되었습니다. .NET SDK에는 기본적으로 프로젝트 디렉토리의 'Content'항목이 포함됩니다.
Javascript 또는 CSS 파일을 asp.net 핵심 프로젝트에 추가하고 dotnet run
bash 터미널에서 실행할 때마다 다음 오류가 발생합니다.
/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft
.NET.Sdk.DefaultItems.targets (188,5) : 오류 : 중복 '콘텐츠'항목이 포함되었습니다. .NET SDK에는 기본적으로 프로젝트 디렉토리의 'Content'항목이 포함됩니다. 프로젝트 파일에서 이러한 항목을 제거하거나 프로젝트 파일에 명시 적으로 포함 시키려면 'EnableDefaultContentItems'속성을 'false'로 설정할 수 있습니다. 자세한 내용은 https://aka.ms/sdkimplicititems를 참조 하십시오 . 중복 항목은 'wwwroot / css / BasicQuotation.css'; 'wwwroot / js / BasicQuotation.js'[/mnt/c/Dev/myproject/MyProject/MyProject.csproj]
빌드가 실패했습니다. 빌드 오류를 수정하고 다시 실행하십시오.
ItemGroup
내 csproj 파일에서 를 제거 하여이 문제를 해결할 수는 있지만 그것이 매우 생산적이라고 생각하지 않습니다.
기본 Visual Studio 2017 ASP.NET 핵심 웹 응용 프로그램 (.NET 핵심) 템플릿에서 발생합니다. wwwroot> js 폴더를 마우스 오른쪽 버튼으로 클릭하여 프로젝트에 파일을 추가 한 다음Add > New Item > JavaScript File
이것은 내 .csproj 파일입니다.
<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="wwwroot\lib\jquery-validation\**" />
<Content Remove="wwwroot\lib\jquery-validation\**" />
<EmbeddedResource Remove="wwwroot\lib\jquery-validation\**" />
<None Remove="wwwroot\lib\jquery-validation\**" />
</ItemGroup>
<ItemGroup>
<Content Include="wwwroot\css\BasicQuotation.css" />
<Content Include="wwwroot\js\BasicQuotation.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="Data\Commands\" />
<Folder Include="Data\Queries\" />
<Folder Include="wwwroot\images\" />
</ItemGroup>
</Project>
그래서 나는이 같은 문제에 부딪쳤다. 문제를 "수정"하지 않는다는 것을 알았 기 때문에 DefaultCompileItems를 끄고 싶지 않았습니다. 그래서 프로젝트를 언로드하고 Visual Studio에서 텍스트 모드로 .csproj 파일을 열어서 이것을 보았습니다.
<ItemGroup>
<Content Include="wwwroot\css\custom-bootstrap-navbar.css" />
<Content Include="wwwroot\images\friends-eating\image1.jpg" />
<Content Include="wwwroot\images\friends-eating\image2.jpg" />
<Content Include="wwwroot\images\friends-eating\image3.jpg" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\images\friends-eating\" />
</ItemGroup>
첫 번째 ItemGroup 블록을 주석 처리했을 때 작동했습니다. 내가 생각하는 것은 프로젝트가 전체 \ images \ friends-eating \ 폴더를 추가 한 다음 각 개별 이미지를 추가하여 중복을 일으키는 것입니다.
As far as the custom css and js, the project automatically adds wwwroot\css and wwwroot\js so if you have an individual file added (like wwwroot\css\custom-bootstrap-navbar.css) it'll count as a duplicate.
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'
This worked in my case:
<PropertyGroup>
...
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>
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 = "wwwroot\xxxxx"
My issues was close but not the exact same. My error was this:
C:\Program Files\dotnet\sdk\2.0.0-preview2-006497\Sdks\Microsoft.NET.Sdk\build\Microsoft.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: 'wwwroot\js\KOBindings.js'; 'wwwroot\js\KOPleaseWait.js'; 'wwwroot\js\ProjectTime\Add.js'; 'wwwroot\js\TimeAdmin\Invoice.js'; 'wwwroot\js\TimeAdmin\PayPeriodTotals.js' [C:\Avantia Projects\Time Card\avantia-timesheet\Solution\Almanac\Almanac.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: 'wwwroot\js\KOBindings.js'; 'wwwroot\js\KOPleaseWait.js'; 'wwwroot\js\ProjectTime\Add.js'; 'wwwroot\js\TimeAdmin\Invoice.js'; 'wwwroot\js\TimeAdmin\PayPeriodTotals.js'
Looking at my .csproj
file:
<ItemGroup>
<Content Include="pdf.js" />
<Content Include="wwwroot\js\package.json" />
<Content Include="wwwroot\js\pdf.js" />
<Content Include="wwwroot\js\KOBindings.js" />
<Content Include="wwwroot\js\KOPleaseWait.js" />
<Content Include="wwwroot\js\ProjectTime\Add.js" />
<Content Include="wwwroot\js\TimeAdmin\Invoice.js" />
<Content Include="wwwroot\js\TimeAdmin\PayPeriodTotals.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="wwwroot\js\package.json" />
<Content Include="wwwroot\js\pdf.js" />
<!--
<Content Include="wwwroot\js\KOBindings.js" />
<Content Include="wwwroot\js\KOPleaseWait.js" />
<Content Include="wwwroot\js\ProjectTime\Add.js" />
<Content Include="wwwroot\js\TimeAdmin\Invoice.js" />
<Content Include="wwwroot\js\TimeAdmin\PayPeriodTotals.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.
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>
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
Actually, Asp.net core automatically include content from wwwroot\css\
, wwwroot\js\
and wwwroot\lib\
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="wwwroot\lib\jquery-validation\**" />
<Content Remove="wwwroot\lib\jquery-validation\**" />
<EmbeddedResource Remove="wwwroot\lib\jquery-validation\**" />
<None Remove="wwwroot\lib\jquery-validation\**" />
</ItemGroup>
<ItemGroup>
<Content Include="wwwroot\css\BasicQuotation.css" />
<Content Include="wwwroot\js\BasicQuotation.js" />
</ItemGroup>
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.
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>
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="wwwroot\theme\favicon.ico" />
<Content Include="wwwroot\theme\fonts\cyrillic-ext400.woff2" />
<Content Include="wwwroot\theme\fonts\cyrillic-ext700.woff2" />
And only add this;
<ItemGroup>
<Folder Include="wwwroot\theme\" />
</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="wwwroot\theme\" />
</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.
.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="Models\ExampleClass.cs" />
<Content ... />
</ItemGroup>
</Project>
My case I is disable both below default items.
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<EnableDefaultItems>false</EnableDefaultItems>
Excluding and Including back the folders that have duplicates error worked for me! Hope this helps someone else!
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.
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.
'Programing' 카테고리의 다른 글
파일 또는 어셈블리 Microsoft.SqlServer.management.sdk.sfc 버전 11.0.0.0을로드 할 수 없습니다 (0) | 2020.07.28 |
---|---|
Rails에서-개행을로 변환하는 rails 방법이 (0) | 2020.07.28 |
Perl에서 전체 파일을 문자열로 읽는 방법은 무엇입니까? (0) | 2020.07.28 |
모든 공백 문자를 교체하십시오 (0) | 2020.07.28 |
정적 메서드 내에서 비 정적 내부 클래스를 인스턴스화하는 방법 (0) | 2020.07.27 |