Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core 1.1 - getting "Duplicate 'Content' items were included"

I've updated my VS2017 to latest 15.3.0 and installed .NET Core SDK 2.0 (I would like to upgrade an existing .NET 1.1 application to 2.0).

Now when I open my project that was compiling fine (didn't change anything in it yet) and I try to compile I get:

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'

Under problematic file it's pointing to C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets

I've read online and I'm able to solve this by adding <EnableDefaultContentItems>false</EnableDefaultContentItems> to my .csproj file. But it wasn't there before and I'm not sure what adding this line means.

Once thing that really bothers me is that the source file it's pointing to is in dotnet\sdk\2.0.0 - and as I mentioned the project is still .NET Core 1.1. All I did so far was to install the update for VS2017 and the 2.0 SDK.

How do I solve this? I would like my original project to compile before I upgrade it to 2.0.

EDIT

My csproj file:

<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>

As mentioned if I add <EnableDefaultContentItems>false</EnableDefaultContentItems> to PropertyGroup it works. But I don't know what is the meaning of this or why it's needed all of a sudden...

like image 960
developer82 Avatar asked Aug 16 '17 04:08

developer82


2 Answers

Remove the <ItemGroup> element containing

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

This item is already included by the Microsoft.NET.Sdk.Web and is therefore defined twice.

like image 183
Martin Ullrich Avatar answered Nov 10 '22 09:11

Martin Ullrich


Necromancing.
Alternatively, do the following:

  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'

The error is now gone.
Much safer than editing by hand.

like image 31
Stefan Steiger Avatar answered Nov 10 '22 09:11

Stefan Steiger