Publishing support
This commit is contained in:
parent
04df5491c2
commit
f7830e7b77
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- TODO: Remove the "PrivateAssets=all" once we no longer have RazorToolingWorkaround.cs -->
|
<!-- TODO: Remove the "PrivateAssets=all" once we no longer have RazorToolingWorkaround.cs -->
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Browser\Microsoft.AspNetCore.Blazor.Browser.csproj" PrivateAssets="all" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Browser\Microsoft.AspNetCore.Blazor.Browser.csproj" PrivateAssets="all" />
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor\Microsoft.AspNetCore.Blazor.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor\Microsoft.AspNetCore.Blazor.csproj" PrivateAssets="all" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Local alternative to <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" /> -->
|
<!-- Local alternative to <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" /> -->
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
<Import Project="RazorCompilation.targets" />
|
<Import Project="RazorCompilation.targets" />
|
||||||
<Import Project="Blazor.MonoRuntime.targets" />
|
<Import Project="Blazor.MonoRuntime.targets" />
|
||||||
|
<Import Project="Publish.targets" />
|
||||||
|
|
||||||
<Target Name="GenerateBlazorMetadataFile" BeforeTargets="GetCopyToOutputDirectoryItems">
|
<Target Name="GenerateBlazorMetadataFile" BeforeTargets="GetCopyToOutputDirectoryItems">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<BlazorLinkOnBuild Condition="'$(Configuration)'=='Release' AND '$(BlazorLinkOnBuild)'==''">true</BlazorLinkOnBuild>
|
||||||
|
<BlazorPublishDistDir>$(AssemblyName)\dist\</BlazorPublishDistDir>
|
||||||
|
|
||||||
|
<!-- Disable unwanted parts of the default publish process -->
|
||||||
|
<CopyBuildOutputToPublishDirectory>false</CopyBuildOutputToPublishDirectory>
|
||||||
|
<CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory>
|
||||||
|
<PreserveCompilationContext>false</PreserveCompilationContext>
|
||||||
|
<RazorCompileOnPublish>false</RazorCompileOnPublish>
|
||||||
|
<GenerateDependencyFile>false</GenerateDependencyFile>
|
||||||
|
<IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Target Name="BlazorGetCopyToPublishDirectoryItems" BeforeTargets="GetCopyToPublishDirectoryItems">
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- Don't want to publish the assemblies from the regular 'bin' dir. Instead we publish ones from 'dist'. -->
|
||||||
|
<ResolvedAssembliesToPublish Remove="@(ResolvedAssembliesToPublish)" />
|
||||||
|
|
||||||
|
<!-- Move wwwroot files to output root -->
|
||||||
|
<ContentWithTargetPath Update="@(ContentWithTargetPath)" Condition="$([System.String]::new(%(TargetPath)).StartsWith('wwwroot\'))">
|
||||||
|
<TargetPath>$(BlazorPublishDistDir)$([System.String]::new(%(TargetPath)).Substring(8))</TargetPath>
|
||||||
|
</ContentWithTargetPath>
|
||||||
|
|
||||||
|
<!-- Publish all the 'dist' files -->
|
||||||
|
<_BlazorGCTPDIDistFiles Include="@(BlazorItemOutput->'%(TargetOutputPath)')" />
|
||||||
|
<_BlazorGCTPDI Include="@(_BlazorGCTPDIDistFiles)">
|
||||||
|
<TargetPath>$(BlazorPublishDistDir)$([MSBuild]::MakeRelative('$(ProjectDir)$(OutDir)dist\', %(Identity)))</TargetPath>
|
||||||
|
</_BlazorGCTPDI>
|
||||||
|
|
||||||
|
<ContentWithTargetPath Include="@(_BlazorGCTPDI)">
|
||||||
|
<TargetPath>%(TargetPath)</TargetPath>
|
||||||
|
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||||
|
</ContentWithTargetPath>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- Replace the .blazor.config contents with what we need to serve in production -->
|
||||||
|
<PropertyGroup>
|
||||||
|
<_BlazorConfigPath>$(OutDir)$(AssemblyName).blazor.config</_BlazorConfigPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<WriteLinesToFile File="$(_BlazorConfigPath)" Lines="." Overwrite="true" />
|
||||||
|
<WriteLinesToFile File="$(_BlazorConfigPath)" Lines="$(AssemblyName)\" Overwrite="false" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- The following target runs only for standalone publishing -->
|
||||||
|
<Target Name="BlazorCompleteStandalonePublish" AfterTargets="CopyFilesToPublishDirectory">
|
||||||
|
<!-- Add a suitable web.config file if there isn't one already -->
|
||||||
|
<ItemGroup>
|
||||||
|
<_StandaloneWebConfigContent Include="$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)Standalone.Web.config'))"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<WriteLinesToFile
|
||||||
|
Condition="!Exists('$(PublishDir)web.config')"
|
||||||
|
File="$(PublishDir)web.config"
|
||||||
|
Lines="@(_StandaloneWebConfigContent->Replace('[ServeSubdirectory]','$(BlazorPublishDistDir)'))" />
|
||||||
|
|
||||||
|
<!-- Remove the .blazor.config file, since it's irrelevant for standalone publishing -->
|
||||||
|
<Delete Files="$(PublishDir)$(AssemblyName).blazor.config" />
|
||||||
|
</Target>
|
||||||
|
</Project>
|
||||||
|
|
@ -19,8 +19,10 @@
|
||||||
<!-- Something quick for input/output tracking - the assumptions here should match what the CLI does -->
|
<!-- Something quick for input/output tracking - the assumptions here should match what the CLI does -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<BlazorGenerate Include="**\*.cshtml" />
|
<BlazorGenerate Include="**\*.cshtml" />
|
||||||
<Content Update="@(Content->WithMetadataValue('Extension', '.cshtml'))">
|
<_BlazorGenerateDeclarationContent Include="@(Content->WithMetadataValue('Extension', '.cshtml'))" />
|
||||||
|
<Content Update="@(_BlazorGenerateDeclarationContent)">
|
||||||
<Generator>MSBuild:BlazorGenerateDeclaration</Generator>
|
<Generator>MSBuild:BlazorGenerateDeclaration</Generator>
|
||||||
|
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
|
||||||
<ProjectCapability Include="DotNetCoreRazorConfiguration" />
|
<ProjectCapability Include="DotNetCoreRazorConfiguration" />
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<system.webServer>
|
||||||
|
<staticContent>
|
||||||
|
<remove fileExtension=".dll" />
|
||||||
|
<mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
|
||||||
|
<mimeMap fileExtension=".wasm" mimeType="application/wasm" />
|
||||||
|
</staticContent>
|
||||||
|
<httpCompression>
|
||||||
|
<dynamicTypes>
|
||||||
|
<add mimeType="application/octet-stream" enabled="true" />
|
||||||
|
<add mimeType="application/wasm" enabled="true" />
|
||||||
|
</dynamicTypes>
|
||||||
|
</httpCompression>
|
||||||
|
<rewrite>
|
||||||
|
<rules>
|
||||||
|
<rule name="Serve subdir">
|
||||||
|
<match url=".*" />
|
||||||
|
<action type="Rewrite" url="[ServeSubdirectory]{R:0}" />
|
||||||
|
</rule>
|
||||||
|
<rule name="SPA fallback routing" stopProcessing="true">
|
||||||
|
<match url=".*" />
|
||||||
|
<conditions logicalGrouping="MatchAll">
|
||||||
|
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
|
||||||
|
</conditions>
|
||||||
|
<action type="Rewrite" url="[ServeSubdirectory]" />
|
||||||
|
</rule>
|
||||||
|
</rules>
|
||||||
|
</rewrite>
|
||||||
|
</system.webServer>
|
||||||
|
</configuration>
|
||||||
|
|
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.StaticFiles;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Builder
|
namespace Microsoft.AspNetCore.Builder
|
||||||
{
|
{
|
||||||
|
|
@ -36,9 +37,15 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
this IApplicationBuilder applicationBuilder,
|
this IApplicationBuilder applicationBuilder,
|
||||||
BlazorOptions options)
|
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 config = BlazorConfig.Read(options.ClientAssemblyPath);
|
||||||
var clientAppBinDir = Path.GetDirectoryName(config.SourceOutputAssemblyPath);
|
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
|
var distDirStaticFiles = new StaticFileOptions
|
||||||
{
|
{
|
||||||
FileProvider = new PhysicalFileProvider(clientAppDistDir),
|
FileProvider = new PhysicalFileProvider(clientAppDistDir),
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,4 @@
|
||||||
<IncludeBuildOutput>False</IncludeBuildOutput>
|
<IncludeBuildOutput>False</IncludeBuildOutput>
|
||||||
<NoWarn>2008</NoWarn>
|
<NoWarn>2008</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk.Razor/2.1.0-preview2-30230">
|
<Project Sdk="Microsoft.NET.Sdk.Razor/2.1.0-preview2-30230;Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue