Inject MSBuild properties into templates during build

This commit is contained in:
Steve Sanderson 2018-04-13 10:16:06 +01:00
parent ce3c79e051
commit ce8088f9a3
21 changed files with 133 additions and 32 deletions

View File

@ -12,6 +12,7 @@
<RestoreSources Condition="'$(DotNetBuildOffline)' != 'true'">
$(RestoreSources);
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/f/blazor-dev/api/v3/index.json;
</RestoreSources>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,3 @@
# We only track the .template.config.src items in source control
# The .template.config files are generated on build
content/**/.template.config/

View File

@ -1,8 +1,7 @@
<Project>
<!--
Left mostly blank to avoid sharing config with the build for the main repo.
For example, we want the templates to declare their own independent package restore sources.
-->
<PropertyGroup>
<TemplateBlazorPackageVersion>0.2.0-preview1-10195</TemplateBlazorPackageVersion>
</PropertyGroup>
<Import Project="../../version.props" />
<Import Project="..\..\Directory.Build.props" />
</Project>

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard20</TargetFramework>
<NuspecFile>Microsoft.AspNetCore.Blazor.Templates.nuspec</NuspecFile>
@ -7,4 +7,38 @@
<IncludeBuildOutput>False</IncludeBuildOutput>
<NoWarn>2008</NoWarn>
</PropertyGroup>
<Target Name="TransformTemplateConfigs" BeforeTargets="CoreBuild" DependsOnTargets="SetTemplateJsonSymbolReplacements">
<!--
For each template, copy its '.template.config.src' directory to '.template.config',
removing any earlier output at that location
-->
<ItemGroup>
<_TemplateConfigMainFile Include="content\**\.template.config.src\template.json" />
<_TemplateConfigDir Include="@(_TemplateConfigMainFile-&gt;'$([System.IO.Path]::GetDirectoryName('%(_TemplateConfigMainFile.FullPath)'))')" />
<_TemplateConfigFileToCopy Include="%(_TemplateConfigDir.Identity)\**\*.*">
<DestDir>$([System.IO.Path]::GetDirectoryName('%(_TemplateConfigDir.Identity)'))\.template.config\</DestDir>
</_TemplateConfigFileToCopy>
</ItemGroup>
<RemoveDir Directories="%(_TemplateConfigFileToCopy.DestDir)" />
<Copy SourceFiles="%(_TemplateConfigFileToCopy.Identity)" DestinationFolder="%(_TemplateConfigFileToCopy.DestDir)" />
<!--
Modify the .json files in the .template.config dirs to stamp MSBuild properties into them
-->
<ItemGroup>
<GeneratedContent Include="@(_TemplateConfigFileToCopy->WithMetadataValue('Extension','.json'))">
<OutputPath>%(DestDir)%(RecursiveDir)%(Filename)%(Extension)</OutputPath>
<Properties>$(GeneratedContentProperties)</Properties>
</GeneratedContent>
</ItemGroup>
<Sdk_GenerateFileFromTemplate
TemplateFile="%(GeneratedContent.Identity)"
Properties="%(GeneratedContent.Properties)"
OutputPath="%(GeneratedContent.OutputPath)">
<Output TaskParameter="OutputPath" ItemName="FileWrites" />
<Output TaskParameter="OutputPath" ItemName="Content" />
</Sdk_GenerateFileFromTemplate>
</Target>
</Project>

View File

@ -19,7 +19,7 @@
<files>
<file
src="content/**/*"
exclude="content/BlazorHosted.CSharp.Client/Properties/launchSettings.json;content/BlazorHosted.CSharp.Server/Properties/launchSettings.json;**/node_modules/**;**/bin/**;**/obj/**;**/*.user;**/.vs/**;**/.vscode/**;content/Directory.Build.*"
exclude="content/BlazorHosted.CSharp.Client/Properties/launchSettings.json;content/BlazorHosted.CSharp.Server/Properties/launchSettings.json;**/node_modules/**;**/bin/**;**/obj/**;**/*.user;**/.vs/**;**/.vscode/**;content/Directory.Build.*;**/.template.config.src/**"
target="Content" />
</files>
</package>

View File

@ -1,10 +1,27 @@
<Project>
<Target Name="SetPackageProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<!-- Properties here are injected into the .nuspec file that is bundled into the package -->
<NuspecProperties>
$(NuspecProperties);
version=$(PackageVersion);
</NuspecProperties>
</PropertyGroup>
</Target>
<Target Name="SetTemplateJsonSymbolReplacements">
<PropertyGroup>
<IncludeCustomRestoreSourcesValue Condition="'$(IsFinalBuild)' == 'true'">false</IncludeCustomRestoreSourcesValue>
<IncludeCustomRestoreSourcesValue Condition="'$(IsFinalBuild)' != 'true'">true</IncludeCustomRestoreSourcesValue>
<!--
Properties here will be injected into the template config *.json files
during the build, replacing tokens of the form ${PropertyName}
-->
<GeneratedContentProperties>
IncludeCustomRestoreSources=$(IncludeCustomRestoreSourcesValue);
TemplateBlazorVersion=$(PackageVersion);
</GeneratedContentProperties>
</PropertyGroup>
</Target>
</Project>

View File

@ -86,6 +86,19 @@
"type": "bind",
"binding": "HostIdentifier"
},
"IncludeCustomRestoreSourcesSymbol": {
"type": "parameter",
"datatype": "bool",
"description": "If set, includes restore sources for the Blazor MyGet feed.",
"defaultValue": "${IncludeCustomRestoreSources}"
},
"TemplateBlazorVersionSymbol": {
"type": "parameter",
"datatype": "string",
"description": "Specifies which version of Blazor packages to use.",
"replaces": "$(TemplateBlazorPackageVersion)",
"defaultValue": "${TemplateBlazorVersion}"
},
"skipRestore": {
"type": "parameter",
"datatype": "bool",

View File

@ -1,17 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Exe</OutputType>
<!-- This custom package feed is required only when using nightly builds of Blazor -->
<RestoreSources>$(RestoreSources);https://dotnet.myget.org/f/blazor-dev/api/v3/index.json</RestoreSources>
<RestoreSources Condition="'$(IncludeCustomRestoreSourcesSymbol)'=='true'">
$(RestoreSources);
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/f/blazor-dev/api/v3/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.0-preview2-final" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.2.0-preview1-10195" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.2.0-preview1-10195" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="$(TemplateBlazorPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="$(TemplateBlazorPackageVersion)" />
</ItemGroup>
<ItemGroup>

View File

@ -1,19 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<!-- This custom package feed is required only when using nightly builds of Blazor -->
<RestoreSources>$(RestoreSources);https://dotnet.myget.org/f/blazor-dev/api/v3/index.json</RestoreSources>
<RestoreSources Condition="'$(IncludeCustomRestoreSourcesSymbol)'=='true'">
$(RestoreSources);
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/f/blazor-dev/api/v3/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup Condition="'$(Framework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="0.2.0-preview1-10195" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="$(TemplateBlazorPackageVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(Framework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="0.2.0-preview1-10195" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="$(TemplateBlazorPackageVersion)" />
</ItemGroup>
<ItemGroup>

View File

@ -47,6 +47,19 @@
"type": "bind",
"binding": "HostIdentifier"
},
"IncludeCustomRestoreSourcesSymbol": {
"type": "parameter",
"datatype": "bool",
"description": "If set, includes restore sources for the Blazor MyGet feed.",
"defaultValue": "${IncludeCustomRestoreSources}"
},
"TemplateBlazorVersionSymbol": {
"type": "parameter",
"datatype": "string",
"description": "Specifies which version of Blazor packages to use.",
"replaces": "$(TemplateBlazorPackageVersion)",
"defaultValue": "${TemplateBlazorVersion}"
},
"skipRestore": {
"type": "parameter",
"datatype": "bool",

View File

@ -1,13 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>library</OutputType>
<IsPackable>true</IsPackable>
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
<!-- This custom package feed is required only when using nightly builds of Blazor -->
<RestoreSources>https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;$(RestoreSources)</RestoreSources>
<RestoreSources Condition="'$(IncludeCustomRestoreSourcesSymbol)'=='true'">
$(RestoreSources);
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/f/blazor-dev/api/v3/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup>
@ -19,8 +21,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.0-preview2-final" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.2.0-preview1-10195" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.2.0-preview1-10195" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="$(TemplateBlazorPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="$(TemplateBlazorPackageVersion)" />
</ItemGroup>
</Project>

View File

@ -65,6 +65,19 @@
},
"replaces": "61501"
},
"IncludeCustomRestoreSourcesSymbol": {
"type": "parameter",
"datatype": "bool",
"description": "If set, includes restore sources for the Blazor MyGet feed.",
"defaultValue": "${IncludeCustomRestoreSources}"
},
"TemplateBlazorVersionSymbol": {
"type": "parameter",
"datatype": "string",
"description": "Specifies which version of Blazor packages to use.",
"replaces": "$(TemplateBlazorPackageVersion)",
"defaultValue": "${TemplateBlazorVersion}"
},
"skipRestore": {
"type": "parameter",
"datatype": "bool",

View File

@ -1,19 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RunCommand>dotnet</RunCommand>
<RunArguments>blazor serve</RunArguments>
<!-- This custom package feed is required only when using nightly builds of Blazor -->
<RestoreSources>$(RestoreSources);https://dotnet.myget.org/f/blazor-dev/api/v3/index.json</RestoreSources>
<RestoreSources Condition="'$(IncludeCustomRestoreSourcesSymbol)'=='true'">
$(RestoreSources);
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/f/blazor-dev/api/v3/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.0-preview2-final" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.2.0-preview1-10195" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.2.0-preview1-10195" />
<DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="0.2.0-preview1-10195" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="$(TemplateBlazorPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="$(TemplateBlazorPackageVersion)" />
<DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="$(TemplateBlazorPackageVersion)" />
</ItemGroup>
</Project>