Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article applies to: ✔️ .NET Core 2.1.100 SDK and later versions
Starting in Visual Studio 2017 / MSBuild version 15.3, the .NET SDK automatically includes items from the project directory by default. These items include Compile and Content targets. This behavior simplifies project files.
However, if you explicitly define any of these items in your project file, you're likely to get a build error similar to the following:
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.
Duplicate 'EmbeddedResource' items were included. The .NET SDK includes 'EmbeddedResource' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultEmbeddedResourceItems' property to 'false' if you want to explicitly include them in your project file.
To resolve the errors, do one of the following:
Remove the explicit
Compile,EmbeddedResource, orNoneitems that match the implicit ones listed on the previous table.Set the EnableDefaultItems property to
falseto disable all implicit file inclusion:<PropertyGroup> <EnableDefaultItems>false</EnableDefaultItems> </PropertyGroup>If you want to specify files to be published with your app, you can still use the known MSBuild mechanisms for that, for example, the
Contentelement.Selectively disable only
Compile,EmbeddedResource, orNoneglobs by setting the EnableDefaultCompileItems, EnableDefaultEmbeddedResourceItems, or EnableDefaultNoneItems property tofalse:<PropertyGroup> <EnableDefaultCompileItems>false</EnableDefaultCompileItems> <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems> <EnableDefaultNoneItems>false</EnableDefaultNoneItems> </PropertyGroup>If you only disable
Compileglobs, Solution Explorer in Visual Studio still shows *.cs items as part of the project, included asNoneitems. To disable the implicitNoneglob, setEnableDefaultNoneItemstofalsetoo.
WPF projects
You might hit this error in a WPF project due to duplicate ApplicationDefinition or Page items. To resolve the error, can you disable default items using an MSBuild property. For example, to disable default Page items in a WPF project, set EnableDefaultPageItems to false:
<PropertyGroup>
<EnableDefaultPageItems>false</EnableDefaultPageItems>
</PropertyGroup>
For more information, see Errors related to duplicate items (WPF).