Skip to content

Commit 62e33da

Browse files
authored
Conditionally enable content items in the razor SDK (#589)
* Move the globs from the project system into the Razor SDK on a separate file that can be imported by itself. * Import the file conditionally based on the EnableRazorContent property
1 parent 4597bc3 commit 62e33da

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!--
2+
***********************************************************************************************
3+
Sdk.Razor.StaticAssets.ProjectSystem.props
4+
5+
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6+
created a backup copy. Incorrect changes to this file will make it
7+
impossible to load or build your projects from the command-line or the IDE.
8+
9+
Copyright (c) .NET Foundation. All rights reserved.
10+
***********************************************************************************************
11+
-->
12+
<Project ToolsVersion="14.0">
13+
14+
<!-- Properties for supporting static content -->
15+
<PropertyGroup>
16+
17+
<!-- This is a contract we have with the Web SDK to allow them in the future to import this file
18+
instead of the whole SDK if needed.
19+
-->
20+
<_WebProjectSystemGlobsPropsDefined>true</_WebProjectSystemGlobsPropsDefined>
21+
22+
<DefaultItemExcludes>$(DefaultItemExcludes);**\node_modules\**;node_modules\**</DefaultItemExcludes>
23+
<DefaultItemExcludes>$(DefaultItemExcludes);**\jspm_packages\**;jspm_packages\**</DefaultItemExcludes>
24+
<DefaultItemExcludes>$(DefaultItemExcludes);**\bower_components\**;bower_components\**</DefaultItemExcludes>
25+
<DefaultWebContentItemExcludes>$(DefaultWebContentItemExcludes);wwwroot\**</DefaultWebContentItemExcludes>
26+
</PropertyGroup>
27+
28+
<ItemGroup Condition="'$(EnableDefaultItems)' == 'true' And '$(EnableDefaultContentItems)' == 'true' ">
29+
<!-- Publish everything under wwwroot, all JSON files, all config files and all Razor files -->
30+
<Content Include="wwwroot\**" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
31+
<Content Include="**\*.config" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(DefaultWebContentItemExcludes)" />
32+
<Content Include="**\*.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(DefaultWebContentItemExcludes)" />
33+
34+
<!-- Set CopyToPublishDirectory to Never for items under AppDesignerFolder ("Properties", by default) to avoid publishing launchSettings.json -->
35+
<Content Update="$(AppDesignerFolder)\**" CopyToPublishDirectory="Never" Condition="'$(AppDesignerFolder)' != ''"/>
36+
37+
<!-- Remove Content items from other item types (in a way that CPS understands) -->
38+
<None Remove="wwwroot\**;**\*.json;**\*.config" />
39+
<Compile Remove="wwwroot\**" />
40+
<EmbeddedResource Remove="wwwroot\**" />
41+
42+
<!-- Keep track of the default content items for later to distinguish them from newly generated content items -->
43+
<!-- It's important to keep this here so that it works well with the Web SDK -->
44+
<_ContentIncludedByDefault Include="@(Content)" />
45+
46+
</ItemGroup>
47+
48+
</Project>

src/Razor/src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Sdk.Razor.CurrentVersion.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,8 @@ Copyright (c) .NET Foundation. All rights reserved.
7474
<None Remove="**\*.razor" />
7575
</ItemGroup>
7676

77+
<Import
78+
Project="$(MSBuildThisFileDirectory)..\..\Sdk\Sdk.Razor.StaticAssets.ProjectSystem.props"
79+
Condition=" '$(EnableRazorSdkContent)' == 'true' " />
80+
7781
</Project>

src/Razor/src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Sdk.Razor.CurrentVersion.targets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Copyright (c) .NET Foundation. All rights reserved.
1010
***********************************************************************************************
1111
-->
1212
<Project ToolsVersion="14.0" TreatAsLocalProperty="_RazorSdkTasksTFM;_Targeting30OrNewerRazorLangVersion">
13+
14+
<PropertyGroup>
15+
<EnableDefaultContentItems Condition=" '$(EnableDefaultContentItems)' == '' ">true</EnableDefaultContentItems>
16+
</PropertyGroup>
17+
1318
<!--
1419
Targets supporting Razor MSBuild integration. Contain support for generating C# code using Razor
1520
and including the generated code in the project lifecycle, including compiling, publishing and producing

0 commit comments

Comments
 (0)