Skip to content

Commit 5cbfd78

Browse files
committed
Fixup
1 parent 37727f2 commit 5cbfd78

22 files changed

+254
-40
lines changed

src/Razor/Microsoft.AspNetCore.Razor.Tools/src/BrotliCompressCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ protected override Task<int> ExecuteCoreAsync()
5656
var source = Sources.Values[i];
5757
var output = Outputs.Values[i];
5858

59-
Directory.CreateDirectory(Path.GetDirectoryName(output));
60-
6159
using var sourceStream = File.OpenRead(source);
6260
using var fileStream = new FileStream(output, FileMode.Create);
6361

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildIntegrationTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public async Task Build_Works_WhenFilesAtDifferentPathsHaveSameNamespaceHierarch
119119
[InitializeTestProject("SimpleMvc")]
120120
public async Task Build_RazorOutputPath_SetToNonDefault()
121121
{
122-
var customOutputPath = Path.Combine("bin", Configuration, TargetFramework, "Razor");
122+
var customOutputPath = Path.Combine("bin", Configuration, Project.TargetFramework, "Razor");
123123
var result = await DotnetMSBuild("Build", $"/p:RazorOutputPath={customOutputPath}");
124124

125125
Assert.BuildPassed(result);
@@ -135,7 +135,7 @@ public async Task Build_RazorOutputPath_SetToNonDefault()
135135
[InitializeTestProject("SimpleMvc")]
136136
public async Task Build_MvcRazorOutputPath_SetToNonDefault()
137137
{
138-
var customOutputPath = Path.Combine("bin", Configuration, TargetFramework, "Razor");
138+
var customOutputPath = Path.Combine("bin", Configuration, Project.TargetFramework, "Razor");
139139
var result = await DotnetMSBuild("Build", $"/p:MvcRazorOutputPath={customOutputPath}");
140140

141141
Assert.BuildPassed(result);

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildWithComponents31IntegrationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public BuildWithComponents31IntegrationTest(BuildServerTestFixture buildServer)
1818
[InitializeTestProject("blazor31")]
1919
public async Task Build_Components_WithDotNetCoreMSBuild_Works()
2020
{
21-
TargetFramework = "netcoreapp3.1";
21+
Project.TargetFramework = "netcoreapp3.1";
2222
var result = await DotnetMSBuild("Build");
2323

2424
Assert.BuildPassed(result);

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildWithComponentsIntegrationTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public async Task Build_Successful_WhenThereAreWarnings()
6767
[InitializeTestProject("ComponentLibrary")]
6868
public async Task Build_WithoutRazorLangVersion_ProducesWarning()
6969
{
70-
TargetFramework = "netstandard2.0";
70+
Project.TargetFramework = "netstandard2.0";
7171
var result = await DotnetMSBuild("Build", "/p:RazorLangVersion=");
7272

7373
Assert.BuildPassed(result, allowWarnings: true);
@@ -80,7 +80,7 @@ public async Task Build_WithoutRazorLangVersion_ProducesWarning()
8080
[InitializeTestProject("ComponentLibrary")]
8181
public async Task Building_NetstandardComponentLibrary()
8282
{
83-
TargetFramework = "netstandard2.0";
83+
Project.TargetFramework = "netstandard2.0";
8484

8585
// Build
8686
var result = await DotnetMSBuild("Build");
@@ -96,7 +96,7 @@ public async Task Building_NetstandardComponentLibrary()
9696
[InitializeTestProject("ComponentLibrary")]
9797
public async Task Build_DoesNotProduceRefsDirectory()
9898
{
99-
TargetFramework = "netstandard2.0";
99+
Project.TargetFramework = "netstandard2.0";
100100

101101
// Build
102102
var result = await DotnetMSBuild("Build");
@@ -111,7 +111,7 @@ public async Task Build_DoesNotProduceRefsDirectory()
111111
[InitializeTestProject("ComponentLibrary")]
112112
public async Task Publish_DoesNotProduceRefsDirectory()
113113
{
114-
TargetFramework = "netstandard2.0";
114+
Project.TargetFramework = "netstandard2.0";
115115

116116
// Build
117117
var result = await DotnetMSBuild("Publish");

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/DesignTimeBuildIntegrationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public async Task RazorGenerateDesignTime_ReturnsRazorGenerateWithTargetPath()
6969
[InitializeTestProject("ComponentLibrary")]
7070
public async Task RazorGenerateComponentDesignTime_ReturnsRazorComponentWithTargetPath()
7171
{
72-
TargetFramework = "netstandard2.0";
72+
Project.TargetFramework = "netstandard2.0";
7373

7474
var result = await DotnetMSBuild("RazorGenerateComponentDesignTime;_IntrospectRazorComponentWithTargetPath");
7575

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/MSBuildIntegrationTestBase.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ protected MSBuildIntegrationTestBase(BuildServerTestFixtureBase buildServer)
3030
#error Configuration not supported
3131
#endif
3232

33-
protected string IntermediateOutputPath => Path.Combine("obj", Configuration, TargetFramework);
33+
protected string IntermediateOutputPath => Path.Combine("obj", Configuration, Project.TargetFramework);
3434

35-
protected string OutputPath => Path.Combine("bin", Configuration, TargetFramework);
35+
protected string OutputPath => Path.Combine("bin", Configuration, Project.TargetFramework);
3636

3737
protected string PublishOutputPath => Path.Combine(OutputPath, "publish");
3838

@@ -49,12 +49,6 @@ internal static ProjectDirectory Project
4949

5050
protected string RazorComponentIntermediateOutputPath => Path.Combine(IntermediateOutputPath, "RazorDeclaration");
5151

52-
internal static string TargetFramework
53-
{
54-
get => Project.TargetFramework;
55-
set => Project.TargetFramework = value;
56-
}
57-
5852
protected BuildServerTestFixtureBase BuildServer { get; set; }
5953

6054
internal Task<MSBuildResult> DotnetMSBuild(

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/MvcBuildIntegrationTestLegacy.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class MvcBuildIntegrationTestLegacy :
1414
IClassFixture<LegacyBuildServerTestFixture>
1515
{
1616
public abstract string TestProjectName { get; }
17-
public abstract new string TargetFramework { get; }
17+
public abstract string TargetFramework { get; }
1818
public virtual string OutputFileName => $"{TestProjectName}.dll";
1919

2020
public MvcBuildIntegrationTestLegacy(LegacyBuildServerTestFixture buildServer)
@@ -25,7 +25,7 @@ public MvcBuildIntegrationTestLegacy(LegacyBuildServerTestFixture buildServer)
2525
protected IDisposable CreateTestProject()
2626
{
2727
Project = ProjectDirectory.Create(TestProjectName);
28-
MSBuildIntegrationTestBase.TargetFramework = TargetFramework;
28+
Project.TargetFramework = TargetFramework;
2929

3030
return new Disposable();
3131
}
@@ -52,7 +52,6 @@ public virtual async Task Building_Project()
5252
result,
5353
Path.Combine(IntermediateOutputPath, $"{TestProjectName}.TagHelpers.output.cache"),
5454
@"""Name"":""SimpleMvc.SimpleTagHelper""");
55-
5655
}
5756
}
5857

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/PackIntegrationTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public async Task Pack_NoBuild_IncludesStaticWebAssets()
258258
[InitializeTestProject("ComponentLibrary")]
259259
public async Task Pack_DoesNotIncludeAnyCustomPropsFiles_WhenNoStaticAssetsAreAvailable()
260260
{
261-
MSBuildIntegrationTestBase.TargetFramework = "netstandard2.0";
261+
Project.TargetFramework = "netstandard2.0";
262262

263263
var result = await DotnetMSBuild("Pack");
264264

@@ -282,7 +282,7 @@ public async Task Pack_DoesNotIncludeAnyCustomPropsFiles_WhenNoStaticAssetsAreAv
282282
[InitializeTestProject("PackageLibraryTransitiveDependency")]
283283
public async Task Pack_Incremental_DoesNotRegenerateCacheAndPropsFiles()
284284
{
285-
TargetFramework = "netstandard2.0";
285+
Project.TargetFramework = "netstandard2.0";
286286
var result = await DotnetMSBuild("Pack");
287287

288288
Assert.BuildPassed(result, allowWarnings: true);

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/Wasm/WasmBuildIntegrationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public async Task Build_ProducesBootJsonDataWithExpectedContent()
109109
public async Task Build_InRelease_ProducesBootJsonDataWithExpectedContent()
110110
{
111111
// Arrange
112-
var project = ProjectDirectory.Create("blazorwasm", additionalProjects: new[] { "razorclasslibrary" });
112+
using var project = ProjectDirectory.Create("blazorwasm", additionalProjects: new[] { "razorclasslibrary" });
113113
project.Configuration = "Release";
114114
var result = await MSBuildProcessManager.DotnetMSBuild(project);
115115

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.IO;
5+
using System.Text.Json;
6+
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Razor.Tasks;
8+
using Xunit;
9+
10+
namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
11+
{
12+
public class WasmBuildLazyLoadTest
13+
{
14+
[Fact]
15+
public async Task Build_LazyLoadExplicitAssembly_Debug_Works()
16+
{
17+
// Arrange
18+
using var project = ProjectDirectory.Create("blazorwasm", additionalProjects: new[] { "razorclasslibrary" });
19+
project.Configuration = "Debug";
20+
21+
project.AddProjectFileContent(
22+
@"
23+
<ItemGroup>
24+
<BlazorWebAssemblyLazyLoad Include='RazorClassLibrary' />
25+
</ItemGroup>
26+
");
27+
28+
var result = await MSBuildProcessManager.DotnetMSBuild(project);
29+
30+
var buildOutputDirectory = project.BuildOutputDirectory;
31+
32+
// Verify that a blazor.boot.json file has been created
33+
Assert.FileExists(result, buildOutputDirectory, "wwwroot", "_framework", "blazor.boot.json");
34+
// And that the assembly is in the output
35+
Assert.FileExists(result, buildOutputDirectory, "wwwroot", "_framework", "RazorClassLibrary.dll");
36+
37+
var bootJson = ReadBootJsonData(result, Path.Combine(buildOutputDirectory, "wwwroot", "_framework", "blazor.boot.json"));
38+
39+
// And that it has been labelled as a dynamic assembly in the boot.json
40+
var dynamicAssemblies = bootJson.resources.dynamicAssembly;
41+
var assemblies = bootJson.resources.assembly;
42+
43+
Assert.NotNull(dynamicAssemblies);
44+
Assert.Contains("RazorClassLibrary.dll", dynamicAssemblies.Keys);
45+
Assert.DoesNotContain("RazorClassLibrary.dll", assemblies.Keys);
46+
47+
// App assembly should not be lazy loaded
48+
Assert.DoesNotContain("blazorwasm.dll", dynamicAssemblies.Keys);
49+
Assert.Contains("blazorwasm.dll", assemblies.Keys);
50+
}
51+
52+
[Fact]
53+
public async Task Build_LazyLoadExplicitAssembly_Release_Works()
54+
{
55+
// Arrange
56+
using var project = ProjectDirectory.Create("blazorwasm", additionalProjects: new[] { "razorclasslibrary" });
57+
project.Configuration = "Release";
58+
59+
project.AddProjectFileContent(
60+
@"
61+
<ItemGroup>
62+
<BlazorWebAssemblyLazyLoad Include='RazorClassLibrary' />
63+
</ItemGroup>
64+
");
65+
66+
var result = await MSBuildProcessManager.DotnetMSBuild(project);
67+
68+
var buildOutputDirectory = project.BuildOutputDirectory;
69+
70+
// Verify that a blazor.boot.json file has been created
71+
Assert.FileExists(result, buildOutputDirectory, "wwwroot", "_framework", "blazor.boot.json");
72+
// And that the assembly is in the output
73+
Assert.FileExists(result, buildOutputDirectory, "wwwroot", "_framework", "RazorClassLibrary.dll");
74+
75+
var bootJson = ReadBootJsonData(result, Path.Combine(buildOutputDirectory, "wwwroot", "_framework", "blazor.boot.json"));
76+
77+
// And that it has been labelled as a dynamic assembly in the boot.json
78+
var dynamicAssemblies = bootJson.resources.dynamicAssembly;
79+
var assemblies = bootJson.resources.assembly;
80+
81+
Assert.NotNull(dynamicAssemblies);
82+
Assert.Contains("RazorClassLibrary.dll", dynamicAssemblies.Keys);
83+
Assert.DoesNotContain("RazorClassLibrary.dll", assemblies.Keys);
84+
85+
// App assembly should not be lazy loaded
86+
Assert.DoesNotContain("blazorwasm.dll", dynamicAssemblies.Keys);
87+
Assert.Contains("blazorwasm.dll", assemblies.Keys);
88+
}
89+
90+
[Fact]
91+
public async Task Publish_LazyLoadExplicitAssembly_Debug_Works()
92+
{
93+
// Arrange
94+
using var project = ProjectDirectory.Create("blazorwasm", additionalProjects: new[] { "razorclasslibrary" });
95+
project.Configuration = "Debug";
96+
97+
project.AddProjectFileContent(
98+
@"
99+
<ItemGroup>
100+
<BlazorWebAssemblyLazyLoad Include='RazorClassLibrary' />
101+
</ItemGroup>
102+
");
103+
104+
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
105+
106+
var publishDirectory = project.PublishOutputDirectory;
107+
108+
// Verify that a blazor.boot.json file has been created
109+
Assert.FileExists(result, publishDirectory, "wwwroot", "_framework", "blazor.boot.json");
110+
// And that the assembly is in the output
111+
Assert.FileExists(result, publishDirectory, "wwwroot", "_framework", "RazorClassLibrary.dll");
112+
113+
var bootJson = ReadBootJsonData(result, Path.Combine(publishDirectory, "wwwroot", "_framework", "blazor.boot.json"));
114+
115+
// And that it has been labelled as a dynamic assembly in the boot.json
116+
var dynamicAssemblies = bootJson.resources.dynamicAssembly;
117+
var assemblies = bootJson.resources.assembly;
118+
119+
Assert.NotNull(dynamicAssemblies);
120+
Assert.Contains("RazorClassLibrary.dll", dynamicAssemblies.Keys);
121+
Assert.DoesNotContain("RazorClassLibrary.dll", assemblies.Keys);
122+
123+
// App assembly should not be lazy loaded
124+
Assert.DoesNotContain("blazorwasm.dll", dynamicAssemblies.Keys);
125+
Assert.Contains("blazorwasm.dll", assemblies.Keys);
126+
}
127+
128+
[Fact]
129+
public async Task Publish_LazyLoadExplicitAssembly_Release_Works()
130+
{
131+
// Arrange
132+
using var project = ProjectDirectory.Create("blazorwasm", additionalProjects: new[] { "razorclasslibrary" });
133+
project.Configuration = "Release";
134+
135+
project.AddProjectFileContent(
136+
@"
137+
<ItemGroup>
138+
<BlazorWebAssemblyLazyLoad Include='RazorClassLibrary' />
139+
</ItemGroup>
140+
");
141+
142+
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
143+
144+
var publishDirectory = project.PublishOutputDirectory;
145+
146+
// Verify that a blazor.boot.json file has been created
147+
Assert.FileExists(result, publishDirectory, "wwwroot", "_framework", "blazor.boot.json");
148+
// And that the assembly is in the output
149+
Assert.FileExists(result, publishDirectory, "wwwroot", "_framework", "RazorClassLibrary.dll");
150+
151+
var bootJson = ReadBootJsonData(result, Path.Combine(publishDirectory, "wwwroot", "_framework", "blazor.boot.json"));
152+
153+
// And that it has been labelled as a dynamic assembly in the boot.json
154+
var dynamicAssemblies = bootJson.resources.dynamicAssembly;
155+
var assemblies = bootJson.resources.assembly;
156+
157+
Assert.NotNull(dynamicAssemblies);
158+
Assert.Contains("RazorClassLibrary.dll", dynamicAssemblies.Keys);
159+
Assert.DoesNotContain("RazorClassLibrary.dll", assemblies.Keys);
160+
161+
// App assembly should not be lazy loaded
162+
Assert.DoesNotContain("blazorwasm.dll", dynamicAssemblies.Keys);
163+
Assert.Contains("blazorwasm.dll", assemblies.Keys);
164+
}
165+
166+
private static BootJsonData ReadBootJsonData(MSBuildResult result, string path)
167+
{
168+
return JsonSerializer.Deserialize<BootJsonData>(
169+
File.ReadAllText(Path.Combine(result.Project.DirectoryPath, path)),
170+
new JsonSerializerOptions(JsonSerializerDefaults.Web));
171+
}
172+
}
173+
}

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/Wasm/WasmCompressionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public async Task Publish_WithLinkerAndCompression_IsIncremental()
9090
var buildOutputDirectory = project.BuildOutputDirectory;
9191

9292
// Act
93-
var compressedFilesFolder = Path.Combine("..", "blazorwasm", project.IntermediateOutputDirectory, "compressed");
93+
var compressedFilesFolder = Path.Combine("..", "blazorwasm", project.IntermediateOutputDirectory, "brotli");
9494
var thumbPrint = FileThumbPrint.CreateFolderThumbprint(project, compressedFilesFolder);
9595

9696
// Assert
@@ -120,7 +120,7 @@ public async Task Publish_WithoutLinkerAndCompression_IsIncremental()
120120
var buildOutputDirectory = project.BuildOutputDirectory;
121121

122122
// Act
123-
var compressedFilesFolder = Path.Combine("..", "blazorwasm", project.IntermediateOutputDirectory, "compressed");
123+
var compressedFilesFolder = Path.Combine("..", "blazorwasm", project.IntermediateOutputDirectory, "brotli");
124124
var thumbPrint = FileThumbPrint.CreateFolderThumbprint(project, compressedFilesFolder);
125125

126126
// Assert

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/Wasm/WasmPublishIntegrationTest.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class WasmPublishIntegrationTest
2121
public async Task Publish_WithDefaultSettings_Works()
2222
{
2323
// Arrange
24-
var project = ProjectDirectory.Create("blazorwasm", additionalProjects: new[] { "razorclasslibrary", "LinkBaseToWebRoot" });
24+
using var project = ProjectDirectory.Create("blazorwasm", additionalProjects: new[] { "razorclasslibrary", "LinkBaseToWebRoot" });
2525
project.Configuration = "Debug";
2626
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
2727

@@ -32,6 +32,7 @@ public async Task Publish_WithDefaultSettings_Works()
3232
var blazorPublishDirectory = Path.Combine(publishDirectory, "wwwroot");
3333

3434
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
35+
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.webassembly.js");
3536
Assert.FileExists(result, blazorPublishDirectory, "_framework", "dotnet.wasm");
3637
Assert.FileExists(result, blazorPublishDirectory, "_framework", DotNetJsFileName);
3738
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazorwasm.dll");
@@ -77,6 +78,7 @@ public async Task Publish_InRelease_Works()
7778
var blazorPublishDirectory = Path.Combine(publishDirectory, "wwwroot");
7879

7980
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
81+
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.webassembly.js");
8082
Assert.FileExists(result, blazorPublishDirectory, "_framework", "dotnet.wasm");
8183
Assert.FileExists(result, blazorPublishDirectory, "_framework", DotNetJsFileName);
8284
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazorwasm.dll");
@@ -138,6 +140,7 @@ public async Task Publish_WithNoBuild_Works()
138140
var blazorPublishDirectory = Path.Combine(publishDirectory, "wwwroot");
139141

140142
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
143+
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.webassembly.js");
141144
Assert.FileExists(result, blazorPublishDirectory, "_framework", "dotnet.wasm");
142145
Assert.FileExists(result, blazorPublishDirectory, "_framework", DotNetJsFileName);
143146
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazorwasm.dll");
@@ -195,6 +198,7 @@ public async Task Publish_WithTrimmingdDisabled_Works()
195198
var blazorPublishDirectory = Path.Combine(publishDirectory, "wwwroot");
196199

197200
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
201+
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.webassembly.js");
198202
Assert.FileExists(result, blazorPublishDirectory, "_framework", "dotnet.wasm");
199203
Assert.FileExists(result, blazorPublishDirectory, "_framework", DotNetJsFileName);
200204
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazorwasm.dll");
@@ -272,6 +276,7 @@ public async Task Publish_HostedApp_DefaultSettings_Works()
272276

273277
var blazorPublishDirectory = Path.Combine(publishDirectory, "wwwroot");
274278
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
279+
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.webassembly.js");
275280
Assert.FileExists(result, blazorPublishDirectory, "_framework", "dotnet.wasm");
276281
Assert.FileExists(result, blazorPublishDirectory, "_framework", DotNetJsFileName);
277282
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazorwasm.dll");

0 commit comments

Comments
 (0)