Skip to content

Commit 2a97de0

Browse files
authored
Fix intermediate path for service worker assets (#21128)
1 parent 147f575 commit 2a97de0

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/Components/WebAssembly/Build/src/targets/ServiceWorkerAssetsManifest.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
BeforeTargets="_ResolveBlazorOutputs;_ResolveBlazorFilesToCompress">
66

77
<PropertyGroup>
8-
<_ServiceWorkerAssetsManifestIntermediateOutputPath>$(_BlazorIntermediateOutputPath)$(ServiceWorkerAssetsManifest)</_ServiceWorkerAssetsManifestIntermediateOutputPath>
8+
<_ServiceWorkerAssetsManifestIntermediateOutputPath>$([MSBuild]::MakeRelative($(MSBuildProjectDirectory), $(_BlazorIntermediateOutputPath)))$(ServiceWorkerAssetsManifest)</_ServiceWorkerAssetsManifestIntermediateOutputPath>
99
<_ServiceWorkerAssetsManifestFullPath>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/$(_ServiceWorkerAssetsManifestIntermediateOutputPath)'))</_ServiceWorkerAssetsManifestFullPath>
1010
</PropertyGroup>
1111

@@ -19,7 +19,7 @@
1919
<SourceId>$(PackageId)</SourceId>
2020
<ContentRoot>$([MSBuild]::NormalizeDirectory('$(TargetDir)wwwroot\'))</ContentRoot>
2121
<BasePath>$(StaticWebAssetBasePath)</BasePath>
22-
<RelativePath>$([MSBuild]::MakeRelative($([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/$(_BlazorIntermediateOutputPath)')), $(_ServiceWorkerAssetsManifestFullPath)))</RelativePath>
22+
<RelativePath>$(ServiceWorkerAssetsManifest)</RelativePath>
2323
</_ManifestStaticWebAsset>
2424

2525
<StaticWebAsset Include="@(_ManifestStaticWebAsset)" />

src/Components/WebAssembly/Build/test/BuildIntegrationTests/BuildIntegrationTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,30 @@ public async Task Build_WithI8NOption_CopiesI8NAssembliesWithLinkerEnabled()
325325
Assert.FileDoesNotExist(result, buildOutputDirectory, "wwwroot", "_framework", "_bin", "I18N.West.dll");
326326
}
327327

328+
[Fact]
329+
public async Task Build_WithCustomOutputPath_Works()
330+
{
331+
// Arrange
332+
using var project = ProjectDirectory.Create("standalone", additionalProjects: new[] { "razorclasslibrary" });
333+
334+
project.AddDirectoryBuildContent(
335+
@"<PropertyGroup>
336+
<BaseOutputPath>$(MSBuildThisFileDirectory)build\bin\</BaseOutputPath>
337+
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build\obj\</BaseIntermediateOutputPath>
338+
</PropertyGroup>");
339+
340+
var result = await MSBuildProcessManager.DotnetMSBuild(project, args: "/restore");
341+
Assert.BuildPassed(result);
342+
343+
var compressedFilesPath = Path.Combine(
344+
project.DirectoryPath,
345+
"build",
346+
project.IntermediateOutputDirectory,
347+
"compressed");
348+
349+
Assert.True(Directory.Exists(compressedFilesPath));
350+
}
351+
328352
private static GenerateBlazorBootJson.BootJsonData ReadBootJsonData(MSBuildResult result, string path)
329353
{
330354
return JsonSerializer.Deserialize<GenerateBlazorBootJson.BootJsonData>(

src/Components/WebAssembly/Build/test/BuildIntegrationTests/ProjectDirectory.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ internal void AddProjectFileContent(string content)
172172
File.WriteAllText(ProjectFilePath, updated);
173173
}
174174

175+
internal void AddDirectoryBuildContent(string content)
176+
{
177+
if (content == null)
178+
{
179+
throw new ArgumentNullException(nameof(content));
180+
}
181+
182+
var filepath = Path.Combine(DirectoryPath, "Directory.Build.props");
183+
184+
var existing = File.ReadAllText(filepath);
185+
var updated = existing.Replace("<!-- Test Placeholder -->", content);
186+
File.WriteAllText(filepath, updated);
187+
}
188+
175189
public void Dispose()
176190
{
177191
if (PreserveWorkingDirectory)

src/Components/WebAssembly/Build/testassets/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<Project>
22
<Import Project="Before.Directory.Build.props" Condition="Exists('Before.Directory.Build.props')" />
33

4+
<!-- Test Placeholder -->
5+
46
<PropertyGroup>
57
<RepoRoot Condition="'$(RepoRoot)' ==''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), global.json))\</RepoRoot>
68
<ComponentsRoot>$(RepoRoot)src\Components\</ComponentsRoot>

0 commit comments

Comments
 (0)