From f7830e7b77311f4e36f7503605295de899f9892d Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Tue, 13 Mar 2018 13:36:27 +0000 Subject: [PATCH] Publishing support --- .../HostedInAspNet.Client.csproj | 4 +- .../Views/_ViewImports.cshtml | 0 .../targets/All.targets | 1 + .../targets/Publish.targets | 59 +++++++++++++++++++ .../targets/RazorCompilation.targets | 4 +- .../targets/Standalone.Web.config | 31 ++++++++++ .../BlazorAppBuilderExtensions.cs | 9 ++- ...crosoft.AspNetCore.Blazor.Templates.csproj | 5 -- .../BlazorHosted.CSharp.Client.csproj | 2 +- 9 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 samples/HostedInAspNet.Server/Views/_ViewImports.cshtml create mode 100644 src/Microsoft.AspNetCore.Blazor.Build/targets/Publish.targets create mode 100644 src/Microsoft.AspNetCore.Blazor.Build/targets/Standalone.Web.config diff --git a/samples/HostedInAspNet.Client/HostedInAspNet.Client.csproj b/samples/HostedInAspNet.Client/HostedInAspNet.Client.csproj index 736c817a6f..bfb8859610 100644 --- a/samples/HostedInAspNet.Client/HostedInAspNet.Client.csproj +++ b/samples/HostedInAspNet.Client/HostedInAspNet.Client.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -9,7 +9,7 @@ - + diff --git a/samples/HostedInAspNet.Server/Views/_ViewImports.cshtml b/samples/HostedInAspNet.Server/Views/_ViewImports.cshtml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Microsoft.AspNetCore.Blazor.Build/targets/All.targets b/src/Microsoft.AspNetCore.Blazor.Build/targets/All.targets index bb7da3ee87..2d293d8b3c 100644 --- a/src/Microsoft.AspNetCore.Blazor.Build/targets/All.targets +++ b/src/Microsoft.AspNetCore.Blazor.Build/targets/All.targets @@ -14,6 +14,7 @@ + diff --git a/src/Microsoft.AspNetCore.Blazor.Build/targets/Publish.targets b/src/Microsoft.AspNetCore.Blazor.Build/targets/Publish.targets new file mode 100644 index 0000000000..70a58d91b0 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Build/targets/Publish.targets @@ -0,0 +1,59 @@ + + + true + $(AssemblyName)\dist\ + + + false + false + false + false + false + true + + + + + + + + + + $(BlazorPublishDistDir)$([System.String]::new(%(TargetPath)).Substring(8)) + + + + <_BlazorGCTPDIDistFiles Include="@(BlazorItemOutput->'%(TargetOutputPath)')" /> + <_BlazorGCTPDI Include="@(_BlazorGCTPDIDistFiles)"> + $(BlazorPublishDistDir)$([MSBuild]::MakeRelative('$(ProjectDir)$(OutDir)dist\', %(Identity))) + + + + %(TargetPath) + PreserveNewest + + + + + + <_BlazorConfigPath>$(OutDir)$(AssemblyName).blazor.config + + + + + + + + + + <_StandaloneWebConfigContent Include="$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)Standalone.Web.config'))"/> + + + + + + + diff --git a/src/Microsoft.AspNetCore.Blazor.Build/targets/RazorCompilation.targets b/src/Microsoft.AspNetCore.Blazor.Build/targets/RazorCompilation.targets index 6ce0db5615..e8fdb1579d 100644 --- a/src/Microsoft.AspNetCore.Blazor.Build/targets/RazorCompilation.targets +++ b/src/Microsoft.AspNetCore.Blazor.Build/targets/RazorCompilation.targets @@ -19,8 +19,10 @@ - + <_BlazorGenerateDeclarationContent Include="@(Content->WithMetadataValue('Extension', '.cshtml'))" /> + MSBuild:BlazorGenerateDeclaration + Never diff --git a/src/Microsoft.AspNetCore.Blazor.Build/targets/Standalone.Web.config b/src/Microsoft.AspNetCore.Blazor.Build/targets/Standalone.Web.config new file mode 100644 index 0000000000..a25a3fb3e0 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Build/targets/Standalone.Web.config @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Microsoft.AspNetCore.Blazor.Server/BlazorAppBuilderExtensions.cs b/src/Microsoft.AspNetCore.Blazor.Server/BlazorAppBuilderExtensions.cs index 3cc5f41f85..ba8d01fe43 100644 --- a/src/Microsoft.AspNetCore.Blazor.Server/BlazorAppBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Blazor.Server/BlazorAppBuilderExtensions.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.FileProviders; using System.IO; using System.Net.Mime; +using Microsoft.AspNetCore.Hosting; namespace Microsoft.AspNetCore.Builder { @@ -36,9 +37,15 @@ namespace Microsoft.AspNetCore.Builder this IApplicationBuilder applicationBuilder, BlazorOptions options) { + // TODO: Make the .blazor.config file contents sane + // Currently the items in it are bizarre and don't relate to their purpose, + // hence all the path manipulation here. We shouldn't be hardcoding 'dist' here either. + var env = (IHostingEnvironment)applicationBuilder.ApplicationServices.GetService(typeof(IHostingEnvironment)); var config = BlazorConfig.Read(options.ClientAssemblyPath); var clientAppBinDir = Path.GetDirectoryName(config.SourceOutputAssemblyPath); - var clientAppDistDir = Path.Combine(clientAppBinDir, "dist"); + var clientAppDistDir = Path.Combine( + env.ContentRootPath, + Path.Combine(clientAppBinDir, "dist")); var distDirStaticFiles = new StaticFileOptions { FileProvider = new PhysicalFileProvider(clientAppDistDir), diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/Microsoft.AspNetCore.Blazor.Templates.csproj b/src/Microsoft.AspNetCore.Blazor.Templates/Microsoft.AspNetCore.Blazor.Templates.csproj index d314be5149..0579cd70f8 100644 --- a/src/Microsoft.AspNetCore.Blazor.Templates/Microsoft.AspNetCore.Blazor.Templates.csproj +++ b/src/Microsoft.AspNetCore.Blazor.Templates/Microsoft.AspNetCore.Blazor.Templates.csproj @@ -7,9 +7,4 @@ False 2008 - - - true - - diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorHosted.CSharp/BlazorHosted.CSharp.Client/BlazorHosted.CSharp.Client.csproj b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorHosted.CSharp/BlazorHosted.CSharp.Client/BlazorHosted.CSharp.Client.csproj index 21cdb900d1..905455aead 100644 --- a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorHosted.CSharp/BlazorHosted.CSharp.Client/BlazorHosted.CSharp.Client.csproj +++ b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorHosted.CSharp/BlazorHosted.CSharp.Client/BlazorHosted.CSharp.Client.csproj @@ -1,4 +1,4 @@ - + netstandard2.0