.NET Core 1.1 - 包含“重复'内容'项目”

时间:2017-08-16 04:09:11

标签: asp.net-core compiler-errors .net-core asp.net-core-2.0 .net-core-2.0

我已将VS2017更新到最新的15.3.0并安装了.NET Core SDK 2.0(我想将现有的.NET 1.1应用程序升级到2.0)。

现在,当我打开正在编译的项目时(还没改变任何内容)我尝试编译得到:

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\index.html'

在有问题的文件中,它指向C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets

我已在线阅读,我可以通过将<EnableDefaultContentItems>false</EnableDefaultContentItems>添加到我的.csproj文件来解决此问题。但它之前没有,我不确定添加这一行是什么意思。

一旦真正困扰我的事情是它所指向的源文件是dotnet\sdk\2.0.0 - 正如我所提到的,该项目仍然是.NET Core 1.1。到目前为止我所做的就是安装VS2017和2.0 SDK的更新。

我该如何解决这个问题?在将其升级到2.0之前,我希望我的原始项目能够进行编译。

修改

我的csproj文件:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="wwwroot\index.html" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="IdentityServer4" Version="1.5.2" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.1" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
    <PackageReference Include="NLog.Web.AspNetCore" Version="4.4.1" />
  </ItemGroup>
  <ItemGroup>
    <Content Update="appsettings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Update="web.config">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <None Update="NLog.config">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

如上所述,如果我将<EnableDefaultContentItems>false</EnableDefaultContentItems>添加到PropertyGroup,则可行。但我不知道这是什么意思,或者为什么突然需要......

2 个答案:

答案 0 :(得分:6)

删除包含

<ItemGroup>元素
<Content Include="wwwroot\index.html" />

此项目已包含在Microsoft.NET.Sdk.Web中,因此定义了两次。

答案 1 :(得分:1)

Necromancing。
或者,执行以下操作:

  1. 点击显示所有文件&#39;在解决方案资源管理器
  2. 右键点击&#39; wwwroot&#39;选择&#39;从项目中排除&#39;
  3. 右键点击&#39; wwwroot&#39;选择&#39;包括在项目&#39;
  4. 错误现在消失了。
    比手工编辑更安全。