I have an asp.net core 1.1 app.
The .csproj for it has an entry
<EnableDefaultContentItems>false</EnableDefaultContentItems>
When I search for this online, all I find is questions about duplicate content errors. What are the default items being enabled (or rather, not enabled) here? And, has Microsoft documented this somewhere that I should know to look?
NET Core is a runtime to execute applications build on it. ASP.NET Core is a web framework to build web apps, IoT apps, and mobile backends on the top of . NET Core or . NET Framework.
This is part of the new project format, in particular the new Microsoft.NET.Sdk.Web
project SDK that is being used for ASP.NET Core projects.
By default, EnableDefaultContentItems
is set to true
. The SDK’s MSBuild property project then contains the following:
<ItemGroup Condition=" '$(EnableDefaultItems)' == 'true' And '$(EnableDefaultContentItems)' == 'true' ">
<!-- Publish everything under wwwroot, all JSON files, all web.config files and all Razor files -->
<Content Include="wwwroot/**" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
<Content Include="**/web.config" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);wwwroot/**" />
<Content Include="**/*.cshtml" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);wwwroot/**" />
<Content Include="**/*.json" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);wwwroot/**" />
<!-- Set CopyToPublishDirectory to Never for items under AppDesignerFolder ("Properties", by default) to avoid publishing launchSettings.json -->
<Content Update="$(AppDesignerFolder)/**" CopyToPublishDirectory="Never" Condition="'$(AppDesignerFolder)' != ''"/>
<!-- Remove Content items from other item types (in a way that CPS understands) -->
<None Remove="wwwroot/**;**/*.json;**/web.config;**/*.cshtml" />
<Compile Remove="wwwroot/**" />
<EmbeddedResource Remove="wwwroot/**" />
<!-- Keep track of the default content items for later to distinguish them from newly generated content items -->
<_ContentIncludedByDefault Include="@(Content)" />
</ItemGroup>
So basically, EnableDefaultContentItems
makes the project automatically:
wwwroot/
, any web.config
and all .cshtml
and .json
files.Properties/
folder on publishSo if you are using the wwwroot
folder and haven’t changed its name, then it’s advised to just keep the default to avoid having to specify all these exceptions manually within your project. These are just the common defaults that allow you to get your project running quickly without MSBuild getting in your way.
Of course, just because these are the defaults, you could still always have more explicit rules later for individual paths, without having to disable the default content items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With