Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What content items does <EnableDefaultContentItems> enable?

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?

like image 655
tbrownaw Avatar asked Oct 27 '17 21:10

tbrownaw


People also ask

What is the difference between ASP.NET Core and .NET Core?

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.


1 Answers

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:

  • Publish all files in wwwroot/, any web.config and all .cshtml and .json files.
  • Ignore the Properties/ folder on publish
  • Prevent those published content files from being compiled or embedded.

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

like image 107
poke Avatar answered Sep 30 '22 14:09

poke