首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >包含重复的“Content”项目。缺省情况下,.NET SDK包含项目目录中的“Content”项

包含重复的“Content”项目。缺省情况下,.NET SDK包含项目目录中的“Content”项
EN

Stack Overflow用户
提问于 2017-04-10 22:30:19
回答 19查看 65.8K关注 0票数 147

每当我将javascript或css文件添加到我的asp.net核心项目中,并在我的bash终端中执行dotnet run时,我得到以下错误:

/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft

.NET.Sdk.DefaultItems.targets(188,5):错误:包含重复的“Content”项。默认情况下,.NET软件开发工具包包含项目目录中的“Content”项。您可以从项目文件中移除这些项,或者如果要在项目文件中显式包含这些项,请将“”EnableDefaultContentItems“”属性设置为“”false“”。“”有关详细信息,请参阅https://aka.ms/sdkimplicititems。重复的项目是:'wwwroot/css/BasicQuotation.css';'wwwroot/js/BasicQuotation.js‘/mnt/c/Dev/myproject/MyProject/MyProject.csproj

构建失败。请修复生成错误,然后重新运行。

我可以通过从我的csproj文件中删除ItemGroup来解决这个问题,但我不认为这样做的效率很高。

这发生在默认的Visual Studio2017Web核心应用程序(.NET核心)模板中。通过右键单击wwwroot > js文件夹,然后选择Add > New Item > JavaScript File,将文件添加到我的项目中

这是我的.csproj文件:

代码语言:javascript
复制
<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>
EN

回答 19

Stack Overflow用户

回答已采纳

发布于 2017-07-09 13:15:26

所以我遇到了同样的问题。我不想关闭DefaultCompileItems,因为我知道这不会“解决”问题。因此,我卸载了我的项目,并在Visual Studio中以文本模式打开了.csproj文件,并看到了以下内容。

代码语言:javascript
复制
<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\文件夹,然后添加每个单独的图像,这会导致重复。

至于自定义css和js,项目会自动添加wwwroot\css和wwwroot\js,所以如果您添加了一个单独的文件(如wwwroot\css\ custom -bootstrap-navbar.css),它将被视为重复文件。

票数 118
EN

Stack Overflow用户

发布于 2017-08-17 15:46:26

代码语言:javascript
复制
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'
票数 206
EN

Stack Overflow用户

发布于 2017-06-05 11:44:10

这在我的案例中起作用了:

代码语言:javascript
复制
 <PropertyGroup>
    ...
    <EnableDefaultContentItems>false</EnableDefaultContentItems>
  </PropertyGroup>
票数 26
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43325916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档