.Net Core Project changes in Visual Studio 2017 RC (build 26127.00)
For any developer who was using the previous Visual Studio 2017 RC build (26020.00) or previous they may encounter issues when upgrading to the latest release which was made available on the January 27, 2017 (build 26127.00).
Two issues affected me today which I have documented below on the fix, can be fixed easily but sometimes nice to have it pointed out. Obviously please backup and test in your environments !!
Error Duplicate 'Compile' items were included.
You may encounter the following error in your projects -
Error Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. The duplicate items were: 'xxxx.cs' xxx.yyy.zzz C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets
Workaround
In previous versions of the project file you would have found the section within your project file that instructs the compiler to include the source files within the solution, these now seems to be included as default when included so the original entry now creates duplicate classes.
For example, previously you may have within your project.csproj file -
[xml]<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>[/xml]
Simple remove the entire section (ItemGroup which includes the Compile and EmbeddedResource) above which will stop the duplicate error. Files will be included as default.
Warning A PackageReference for 'NETStandard.Library' was included in your project.
The second common error is that either one of the following libraries ( Microsoft.NETCore.App, NETStandard.Library and Microsoft.NET.Sdk ) are included in your project and will raise the error below.
Warning A PackageReference for 'NETStandard.Library' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs xxx.yyy.zzzz C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets
Workaround
Simply edit the associated project.csproj file and rmeove the following line -
[xml]<PackageReference Include="NETStandard.Library" Version="1.6.1" />[/xml]
The include is now implicit for .Net Core project files so does not need to be included in the project references any more.
As with any update it is worth visiting the Release Notes before apply the update and refer to for any other breaking change.
Comments welcome below
Comments
- Anonymous
February 01, 2017
Removing the compile entry seems to break building libraries using dotnet build for me. I used the following in the .csproj instead: ... false- Anonymous
February 01, 2017
Thank you for your response. I have a solution with both .Net core class libraries and ASP.Net Core Web Applications. If I launch the 'Developer Command Prompt for VS2017 RC', navigate to the directory of the solution and run 'dotnet clean' (to make sure) and 'dotnet build' I don't have any issues with building the entire solution. Did you follow this same process ? - Anonymous
December 13, 2017
great answer !!!!!Thank you
- Anonymous
- Anonymous
March 08, 2017
Thank you for posting this. I ran into the duplicate compile issue for a project moving from VS 2017 RC to VS 2017 released yesterday.