每当我在 asp.net 核心项目中添加一个 javascript 或 css 文件并在 bash 终端中执行 dotnet run
时,都会得到以下错误:
/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft
. NET.Sdk. DefaultItems.target (188,5) : error: 重复“ Content” .NETSDK 包括来自您的 默认情况下,您可以从 或将“ EnableDefaultContentItems”属性设置为 “ false”,如果您希望在项目文件中显式包含它们。 有关更多信息,请参见 https://aka.ms/sdkimplicititems 重复的项目是: ‘ wwwroot/css/BasicQuotation.css’; ‘ wwwroot/js/BasicQuotation.js’ [/mnt/c/Dev/MyProject/MyProject/MyProject.csproj ]
生成失败。请修复生成错误并重新运行。
我可以通过从 csproj 文件中删除 ItemGroup
来解决这个问题,但是我不认为这是非常有效的。
这在默认的 VisualStudio2017ASP.NET 核心 Web 应用程序(。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>