4

我已经更新了我的VS2017到最新的15.3.0并安装了.NET Core SDK 2.0(我想将现有的.NET 1.1应用程序升级到2.0 )。.NET核心1.1 - 获取“重复的内容”项目被包括“

现在,当我打开我的项目,该项目编译罚款(没有改变它任何事情),我尝试编译,我得到:

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它的工作原理提及。但我不知道这个是什么意思,或者为什么需要它的突然...

+1

这是您的csproj文件中的问题,您需要分享它以便我们能够帮助您。 –

+0

@MartinUllrich编辑了我的问题 – developer82

回答

5

删除含有

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

此产品的<ItemGroup>元素已经包含在Microsoft.NET.Sdk.Web,因此定义两次。

0

Necromancing。
或者,请执行下列操作:

  1. 在解决方案资源管理器中点击“显示所有文件”
  2. 右键单击在“wwwroot的”选择“从项目中排除”
  3. 右键单击在“wwwroot的”选择“包含in Project'

错误消失。
比手工编辑安全得多。

相关问题