Produce correct blazor.boot.json when using StaticWebAssetBasePath (#29293)
This commit is contained in:
parent
8872b75001
commit
fe37d39281
|
|
@ -970,6 +970,58 @@ $@"<PropertyGroup>
|
|||
Assert.FileDoesNotExist(result, publishOutputDirectory, "wwwroot", "_framework", "icudt_no_CJK.dat");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_HostingMultipleBlazorWebApps_Works()
|
||||
{
|
||||
// Regression test for https://github.com/dotnet/aspnetcore/issues/29264
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("BlazorMultipleApps.Server", "BlazorMultipleApps.FirstClient", "BlazorMultipleApps.SecondClient", "BlazorMultipleApps.Shared");
|
||||
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
|
||||
|
||||
var publishOutputDirectory = project.PublishOutputDirectory;
|
||||
|
||||
Assert.FileExists(result, Path.Combine(publishOutputDirectory, "BlazorMultipleApps.Server.dll"));
|
||||
Assert.FileExists(result, Path.Combine(publishOutputDirectory, "BlazorMultipleApps.FirstClient.dll"));
|
||||
Assert.FileExists(result, Path.Combine(publishOutputDirectory, "BlazorMultipleApps.SecondClient.dll"));
|
||||
|
||||
var firstAppPublishDirectory = Path.Combine(publishOutputDirectory, "wwwroot", "FirstApp");
|
||||
|
||||
var firstCss = Assert.FileExists(result, Path.Combine(firstAppPublishDirectory, "css", "app.css"));
|
||||
Assert.FileContains(result, firstCss, "/* First app.css */");
|
||||
|
||||
var firstBootJsonPath = Path.Combine(firstAppPublishDirectory, "_framework", "blazor.boot.json");
|
||||
var firstBootJson = ReadBootJsonData(result, firstBootJsonPath);
|
||||
|
||||
// Do a sanity check that the boot json has files.
|
||||
Assert.Contains("System.Text.Json.dll", firstBootJson.resources.assembly.Keys);
|
||||
|
||||
VerifyBootManifestHashes(result, firstAppPublishDirectory);
|
||||
|
||||
// Verify compression works
|
||||
Assert.FileExists(result, firstAppPublishDirectory, "_framework", "dotnet.wasm.br");
|
||||
Assert.FileExists(result, firstAppPublishDirectory, "_framework", "BlazorMultipleApps.FirstClient.dll.br");
|
||||
Assert.FileExists(result, firstAppPublishDirectory, "_framework", "System.Text.Json.dll.br");
|
||||
|
||||
var secondAppPublishDirectory = Path.Combine(publishOutputDirectory, "wwwroot", "SecondApp");
|
||||
|
||||
var secondCss = Assert.FileExists(result, Path.Combine(secondAppPublishDirectory, "css", "app.css"));
|
||||
Assert.FileContains(result, secondCss, "/* Second app.css */");
|
||||
|
||||
var secondBootJsonPath = Path.Combine(secondAppPublishDirectory, "_framework", "blazor.boot.json");
|
||||
var secondBootJson = ReadBootJsonData(result, secondBootJsonPath);
|
||||
|
||||
// Do a sanity check that the boot json has files.
|
||||
Assert.Contains("System.Private.CoreLib.dll", secondBootJson.resources.assembly.Keys);
|
||||
|
||||
VerifyBootManifestHashes(result, secondAppPublishDirectory);
|
||||
|
||||
// Verify compression works
|
||||
Assert.FileExists(result, secondAppPublishDirectory, "_framework", "dotnet.wasm.br");
|
||||
Assert.FileExists(result, secondAppPublishDirectory, "_framework", "BlazorMultipleApps.SecondClient.dll.br");
|
||||
Assert.FileExists(result, secondAppPublishDirectory, "_framework", "System.Private.CoreLib.dll.br");
|
||||
Assert.FileDoesNotExist(result, secondAppPublishDirectory, "_framework", "System.Text.Json.dll.br");
|
||||
}
|
||||
|
||||
private static void AddWasmProjectContent(ProjectDirectory project, string content)
|
||||
{
|
||||
var path = Path.Combine(project.SolutionPath, "blazorwasm", "blazorwasm.csproj");
|
||||
|
|
@ -1022,7 +1074,6 @@ $@"<PropertyGroup>
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void VerifyTypeGranularTrimming(MSBuildResult result, string blazorPublishDirectory)
|
||||
{
|
||||
var componentsShimAssemblyPath = Path.Combine(blazorPublishDirectory, "_framework", "Microsoft.AspNetCore.Razor.Test.ComponentShim.dll");
|
||||
|
|
|
|||
|
|
@ -509,7 +509,7 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<ItemGroup>
|
||||
<_BlazorPublishBootResource
|
||||
Include="@(ResolvedFileToPublish)"
|
||||
Condition="$([System.String]::Copy('%(RelativePath)').Replace('\','/').StartsWith('wwwroot/_framework')) AND '%(Extension)' != '.a'" />
|
||||
Condition="$([System.String]::Copy('%(RelativePath)').Replace('\','/').StartsWith($(_BlazorFrameworkPublishPath.Replace('\', '/')))) AND '%(Extension)' != '.a'" />
|
||||
</ItemGroup>
|
||||
|
||||
<GetFileHash Files="@(_BlazorPublishBootResource)" Algorithm="SHA256" HashEncoding="base64">
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
<h1>@typeof(BlazorMultipleApps.FirstClient.Program)</h1>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<StaticWebAssetBasePath>FirstApp</StaticWebAssetBasePath>
|
||||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
<BlazorWebAssemblySdkDirectoryRoot>$(BlazorWebAssemblySdkArtifactsDirectory)$(Configuration)\sdk-output\</BlazorWebAssemblySdkDirectoryRoot>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BlazorMultipleApps.Shared\BlazorMultipleApps.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(BinariesRoot)'==''">
|
||||
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
|
||||
<BinariesRoot>$(RepoRoot)artifacts\bin\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\$(Configuration)\netstandard2.0\</BinariesRoot>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- DO NOT add addition references here. This is meant to simulate a non-MVC library -->
|
||||
<ItemGroup Condition="'$(BinariesRoot)'!=''">
|
||||
<Reference Include="$(BinariesRoot)\Microsoft.AspNetCore.Razor.Test.ComponentShim.dll"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text;
|
||||
|
||||
namespace BlazorMultipleApps.FirstClient
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
GC.KeepAlive(typeof(System.Text.Json.JsonSerializer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
/* First app.css */
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>BlazorMultipleApps</title>
|
||||
<base href="/FirstApp/" />
|
||||
<link href="css/app.css" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="_framework/blazor.webassembly.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -0,0 +1 @@
|
|||
<h1>@typeof(BlazorMultipleApps.SecondClient.Program)</h1>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<StaticWebAssetBasePath>SecondApp</StaticWebAssetBasePath>
|
||||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
<BlazorWebAssemblySdkDirectoryRoot>$(BlazorWebAssemblySdkArtifactsDirectory)$(Configuration)\sdk-output\</BlazorWebAssemblySdkDirectoryRoot>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BlazorMultipleApps.Shared\BlazorMultipleApps.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(BinariesRoot)'==''">
|
||||
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
|
||||
<BinariesRoot>$(RepoRoot)artifacts\bin\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\$(Configuration)\netstandard2.0\</BinariesRoot>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- DO NOT add addition references here. This is meant to simulate a non-MVC library -->
|
||||
<ItemGroup Condition="'$(BinariesRoot)'!=''">
|
||||
<Reference Include="$(BinariesRoot)\Microsoft.AspNetCore.Razor.Test.ComponentShim.dll"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BlazorMultipleApps.SecondClient
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
/* Second app.css */
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>SecondBlazorApp</title>
|
||||
<base href="/SecondApp/" />
|
||||
<link href="css/app.css" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="_framework/blazor.webassembly.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BlazorMultipleApps.SecondClient\BlazorMultipleApps.SecondClient.csproj" />
|
||||
<ProjectReference Include="..\BlazorMultipleApps.FirstClient\BlazorMultipleApps.FirstClient.csproj" />
|
||||
<ProjectReference Include="..\BlazorMultipleApps.Shared\BlazorMultipleApps.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
namespace BlazorMultipleApps.Server
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BlazorMultipleApps.Shared
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public string Summary { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
<ProjectReference Include="..\blazorwasm\blazorwasm.csproj" />
|
||||
<ProjectReference Include="..\blazorwasm-minimal\blazorwasm-minimal.csproj" />
|
||||
<ProjectReference Include="..\blazorwasm-fxref\blazorwasm-fxref.csproj" />
|
||||
<ProjectReference Include="..\BlazorMultipleApps.Server\BlazorMultipleApps.Server.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Reference in New Issue