Skip to content

Commit fe37d39

Browse files
authored
Produce correct blazor.boot.json when using StaticWebAssetBasePath (#29293)
1 parent 8872b75 commit fe37d39

File tree

17 files changed

+209
-2
lines changed

17 files changed

+209
-2
lines changed

src/Components/WebAssembly/Sdk/integrationtests/WasmPublishIntegrationTest.cs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,58 @@ public async Task Publish_WithInvariantGlobalizationEnabled_DoesNotCopyGlobaliza
970970
Assert.FileDoesNotExist(result, publishOutputDirectory, "wwwroot", "_framework", "icudt_no_CJK.dat");
971971
}
972972

973+
[Fact]
974+
public async Task Publish_HostingMultipleBlazorWebApps_Works()
975+
{
976+
// Regression test for https://github.com/dotnet/aspnetcore/issues/29264
977+
// Arrange
978+
using var project = ProjectDirectory.Create("BlazorMultipleApps.Server", "BlazorMultipleApps.FirstClient", "BlazorMultipleApps.SecondClient", "BlazorMultipleApps.Shared");
979+
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
980+
981+
var publishOutputDirectory = project.PublishOutputDirectory;
982+
983+
Assert.FileExists(result, Path.Combine(publishOutputDirectory, "BlazorMultipleApps.Server.dll"));
984+
Assert.FileExists(result, Path.Combine(publishOutputDirectory, "BlazorMultipleApps.FirstClient.dll"));
985+
Assert.FileExists(result, Path.Combine(publishOutputDirectory, "BlazorMultipleApps.SecondClient.dll"));
986+
987+
var firstAppPublishDirectory = Path.Combine(publishOutputDirectory, "wwwroot", "FirstApp");
988+
989+
var firstCss = Assert.FileExists(result, Path.Combine(firstAppPublishDirectory, "css", "app.css"));
990+
Assert.FileContains(result, firstCss, "/* First app.css */");
991+
992+
var firstBootJsonPath = Path.Combine(firstAppPublishDirectory, "_framework", "blazor.boot.json");
993+
var firstBootJson = ReadBootJsonData(result, firstBootJsonPath);
994+
995+
// Do a sanity check that the boot json has files.
996+
Assert.Contains("System.Text.Json.dll", firstBootJson.resources.assembly.Keys);
997+
998+
VerifyBootManifestHashes(result, firstAppPublishDirectory);
999+
1000+
// Verify compression works
1001+
Assert.FileExists(result, firstAppPublishDirectory, "_framework", "dotnet.wasm.br");
1002+
Assert.FileExists(result, firstAppPublishDirectory, "_framework", "BlazorMultipleApps.FirstClient.dll.br");
1003+
Assert.FileExists(result, firstAppPublishDirectory, "_framework", "System.Text.Json.dll.br");
1004+
1005+
var secondAppPublishDirectory = Path.Combine(publishOutputDirectory, "wwwroot", "SecondApp");
1006+
1007+
var secondCss = Assert.FileExists(result, Path.Combine(secondAppPublishDirectory, "css", "app.css"));
1008+
Assert.FileContains(result, secondCss, "/* Second app.css */");
1009+
1010+
var secondBootJsonPath = Path.Combine(secondAppPublishDirectory, "_framework", "blazor.boot.json");
1011+
var secondBootJson = ReadBootJsonData(result, secondBootJsonPath);
1012+
1013+
// Do a sanity check that the boot json has files.
1014+
Assert.Contains("System.Private.CoreLib.dll", secondBootJson.resources.assembly.Keys);
1015+
1016+
VerifyBootManifestHashes(result, secondAppPublishDirectory);
1017+
1018+
// Verify compression works
1019+
Assert.FileExists(result, secondAppPublishDirectory, "_framework", "dotnet.wasm.br");
1020+
Assert.FileExists(result, secondAppPublishDirectory, "_framework", "BlazorMultipleApps.SecondClient.dll.br");
1021+
Assert.FileExists(result, secondAppPublishDirectory, "_framework", "System.Private.CoreLib.dll.br");
1022+
Assert.FileDoesNotExist(result, secondAppPublishDirectory, "_framework", "System.Text.Json.dll.br");
1023+
}
1024+
9731025
private static void AddWasmProjectContent(ProjectDirectory project, string content)
9741026
{
9751027
var path = Path.Combine(project.SolutionPath, "blazorwasm", "blazorwasm.csproj");
@@ -1022,7 +1074,6 @@ static string ParseWebFormattedHash(string webFormattedHash)
10221074
}
10231075
}
10241076

1025-
10261077
private void VerifyTypeGranularTrimming(MSBuildResult result, string blazorPublishDirectory)
10271078
{
10281079
var componentsShimAssemblyPath = Path.Combine(blazorPublishDirectory, "_framework", "Microsoft.AspNetCore.Razor.Test.ComponentShim.dll");

src/Components/WebAssembly/Sdk/src/targets/Microsoft.NET.Sdk.BlazorWebAssembly.Current.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ Copyright (c) .NET Foundation. All rights reserved.
509509
<ItemGroup>
510510
<_BlazorPublishBootResource
511511
Include="@(ResolvedFileToPublish)"
512-
Condition="$([System.String]::Copy('%(RelativePath)').Replace('\','/').StartsWith('wwwroot/_framework')) AND '%(Extension)' != '.a'" />
512+
Condition="$([System.String]::Copy('%(RelativePath)').Replace('\','/').StartsWith($(_BlazorFrameworkPublishPath.Replace('\', '/')))) AND '%(Extension)' != '.a'" />
513513
</ItemGroup>
514514

515515
<GetFileHash Files="@(_BlazorPublishBootResource)" Algorithm="SHA256" HashEncoding="base64">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>@typeof(BlazorMultipleApps.FirstClient.Program)</h1>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<StaticWebAssetBasePath>FirstApp</StaticWebAssetBasePath>
6+
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
7+
<BlazorWebAssemblySdkDirectoryRoot>$(BlazorWebAssemblySdkArtifactsDirectory)$(Configuration)\sdk-output\</BlazorWebAssemblySdkDirectoryRoot>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\BlazorMultipleApps.Shared\BlazorMultipleApps.Shared.csproj" />
12+
</ItemGroup>
13+
14+
<PropertyGroup Condition="'$(BinariesRoot)'==''">
15+
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
16+
<BinariesRoot>$(RepoRoot)artifacts\bin\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\$(Configuration)\netstandard2.0\</BinariesRoot>
17+
</PropertyGroup>
18+
19+
<!-- DO NOT add addition references here. This is meant to simulate a non-MVC library -->
20+
<ItemGroup Condition="'$(BinariesRoot)'!=''">
21+
<Reference Include="$(BinariesRoot)\Microsoft.AspNetCore.Razor.Test.ComponentShim.dll"/>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using System.Text;
5+
6+
namespace BlazorMultipleApps.FirstClient
7+
{
8+
public class Program
9+
{
10+
public static void Main(string[] args)
11+
{
12+
GC.KeepAlive(typeof(System.Text.Json.JsonSerializer));
13+
}
14+
}
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* First app.css */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>BlazorMultipleApps</title>
6+
<base href="/FirstApp/" />
7+
<link href="css/app.css" rel="stylesheet" />
8+
</head>
9+
10+
<body>
11+
<script src="_framework/blazor.webassembly.js"></script>
12+
</body>
13+
14+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>@typeof(BlazorMultipleApps.SecondClient.Program)</h1>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<StaticWebAssetBasePath>SecondApp</StaticWebAssetBasePath>
6+
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
7+
<BlazorWebAssemblySdkDirectoryRoot>$(BlazorWebAssemblySdkArtifactsDirectory)$(Configuration)\sdk-output\</BlazorWebAssemblySdkDirectoryRoot>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\BlazorMultipleApps.Shared\BlazorMultipleApps.Shared.csproj" />
12+
</ItemGroup>
13+
14+
<PropertyGroup Condition="'$(BinariesRoot)'==''">
15+
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
16+
<BinariesRoot>$(RepoRoot)artifacts\bin\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\$(Configuration)\netstandard2.0\</BinariesRoot>
17+
</PropertyGroup>
18+
19+
<!-- DO NOT add addition references here. This is meant to simulate a non-MVC library -->
20+
<ItemGroup Condition="'$(BinariesRoot)'!=''">
21+
<Reference Include="$(BinariesRoot)\Microsoft.AspNetCore.Razor.Test.ComponentShim.dll"/>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace BlazorMultipleApps.SecondClient
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)