Codementor Events

How I Fixed Duplicate 'Compile' items were included in .NET SDK (ASP.NET CORE)

Published Mar 23, 2018
How I Fixed Duplicate 'Compile' items were included in .NET SDK (ASP.NET CORE)

This is an error that usually occurs in Visual Studio 2017 as a result of renaming a file. This kind of error has caused a lot of projects created in Visual to be repeated over and over again if the occurrence of renaming a file happens.

How It Happens

It usually happens as a result of renaming a file in Visual Studio 2017 IDE. In my case, I had a file that contained a couple of classes that I intended to break out into separate files.

None of the classes assumed the name of the file. My file was unsaved and I attempted to rename the file in the IDE to the name of one of the classes. After all of the processes above and trying to build my project, I got the 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.

How to Fix

From the error message, I understand that the project file contains a file to include explicitly in a compile section because the file in question is already compiled to the project path.

The error message will tell you the filename that's having issues.

To fix this error, follow the instruction below:
1. In solution explorer, right click on your project and select Edit project.csproj from the context menu.

The error message will tell you the filename that's having issues and will be in the project.csproj in the format below..

<ItemGroup>
<Compile Include="YourFolder\Namespace\ClassNameHere.cs" />
</ItemGroup>
Kindly locate it and delete the section of both the "Compile" and <ItemGroup></ItemGroup> created automatically by Visual Studio for the effect.

Once done, try and rebuild your project. Now you are good to go.

Happy coding.

Discover and read more posts from Ijatuyi Sunkanmi Temitope
get started
post commentsBe the first to share your opinion
Show more replies