Duplicate #39;Content#39; items were included. The .NET SDK includes #39;Content#39; items from your project directory by default(包含重复的“内容项目.默认情况下,.NET SDK 包含项目目录中的“内容项)
问题描述
每当我将 javascript 或 css 文件添加到我的 asp.net 核心项目并在我的 bash 终端中执行 dotnet run
时,我都会收到以下错误:
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
/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft
.NET.Sdk.DefaultItems.targets(188,5):错误:重复内容"项目包括在内..NET SDK 包括您的内容"项默认项目目录.您可以从您的项目文件,或将EnableDefaultContentItems"属性设置为如果您想将它们明确包含在项目文件中,则为false".有关详细信息,请参阅 https://aka.ms/sdkimplicititems.这重复的项目是:'wwwroot/css/BasicQuotation.css';'wwwroot/js/BasicQuotation.js'[/mnt/c/Dev/myproject/MyProject/MyProject.csproj]
.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.
我可以通过从我的 csproj 文件中删除 ItemGroup
来解决此问题,但我认为这不是很有效率.
I can fix this by removing the ItemGroup
from my csproj file, but I don't think that's very productive.
这发生在默认的 Visual Studio 2017 ASP.NET Core Web 应用程序 (.NET Core) 模板中.我通过右键单击 wwwroot > js 文件夹将文件添加到我的项目,然后选择 Add >新项目 >JavaScript 文件
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
这是我的 .csproj 文件:
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>
推荐答案
所以我遇到了同样的问题.我不想关闭 DefaultCompileItems,因为我知道这不会解决"问题.所以我卸载了我的项目并在 Visual Studio 中以文本模式打开了 .csproj 文件并看到了这个.
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>
当我注释掉第一个 ItemGroup 块时,它起作用了.我假设正在发生的是该项目正在添加整个 imagesfriends-eating 文件夹,然后添加每个单独的图像,从而导致重复.
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.
就自定义 css 和 js 而言,该项目会自动添加 wwwrootcss 和 wwwrootjs,因此如果您添加了单个文件(如 wwwrootcsscustom-bootstrap-navbar.css),它将计为重复.
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.
这篇关于包含重复的“内容"项目.默认情况下,.NET SDK 包含项目目录中的“内容"项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:包含重复的“内容"项目.默认情况下,.NET SDK 包含项目目录中的“内容"项
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01