每当我将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包含项目目录中的“内容”项。您可以从项目文件中删除这些项目,也可以将“ 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 Core Web应用程序(.NET Core)模板中发生。我通过右键单击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>