Fix intermediate path for service worker assets (#21128)

This commit is contained in:
Safia Abdalla 2020-04-30 15:03:16 -07:00 committed by GitHub
parent 147f5758c6
commit 2a97de0344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 2 deletions

View File

@ -5,7 +5,7 @@
BeforeTargets="_ResolveBlazorOutputs;_ResolveBlazorFilesToCompress"> BeforeTargets="_ResolveBlazorOutputs;_ResolveBlazorFilesToCompress">
<PropertyGroup> <PropertyGroup>
<_ServiceWorkerAssetsManifestIntermediateOutputPath>$(_BlazorIntermediateOutputPath)$(ServiceWorkerAssetsManifest)</_ServiceWorkerAssetsManifestIntermediateOutputPath> <_ServiceWorkerAssetsManifestIntermediateOutputPath>$([MSBuild]::MakeRelative($(MSBuildProjectDirectory), $(_BlazorIntermediateOutputPath)))$(ServiceWorkerAssetsManifest)</_ServiceWorkerAssetsManifestIntermediateOutputPath>
<_ServiceWorkerAssetsManifestFullPath>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/$(_ServiceWorkerAssetsManifestIntermediateOutputPath)'))</_ServiceWorkerAssetsManifestFullPath> <_ServiceWorkerAssetsManifestFullPath>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/$(_ServiceWorkerAssetsManifestIntermediateOutputPath)'))</_ServiceWorkerAssetsManifestFullPath>
</PropertyGroup> </PropertyGroup>
@ -19,7 +19,7 @@
<SourceId>$(PackageId)</SourceId> <SourceId>$(PackageId)</SourceId>
<ContentRoot>$([MSBuild]::NormalizeDirectory('$(TargetDir)wwwroot\'))</ContentRoot> <ContentRoot>$([MSBuild]::NormalizeDirectory('$(TargetDir)wwwroot\'))</ContentRoot>
<BasePath>$(StaticWebAssetBasePath)</BasePath> <BasePath>$(StaticWebAssetBasePath)</BasePath>
<RelativePath>$([MSBuild]::MakeRelative($([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/$(_BlazorIntermediateOutputPath)')), $(_ServiceWorkerAssetsManifestFullPath)))</RelativePath> <RelativePath>$(ServiceWorkerAssetsManifest)</RelativePath>
</_ManifestStaticWebAsset> </_ManifestStaticWebAsset>
<StaticWebAsset Include="@(_ManifestStaticWebAsset)" /> <StaticWebAsset Include="@(_ManifestStaticWebAsset)" />

View File

@ -325,6 +325,30 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
Assert.FileDoesNotExist(result, buildOutputDirectory, "wwwroot", "_framework", "_bin", "I18N.West.dll"); Assert.FileDoesNotExist(result, buildOutputDirectory, "wwwroot", "_framework", "_bin", "I18N.West.dll");
} }
[Fact]
public async Task Build_WithCustomOutputPath_Works()
{
// Arrange
using var project = ProjectDirectory.Create("standalone", additionalProjects: new[] { "razorclasslibrary" });
project.AddDirectoryBuildContent(
@"<PropertyGroup>
<BaseOutputPath>$(MSBuildThisFileDirectory)build\bin\</BaseOutputPath>
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build\obj\</BaseIntermediateOutputPath>
</PropertyGroup>");
var result = await MSBuildProcessManager.DotnetMSBuild(project, args: "/restore");
Assert.BuildPassed(result);
var compressedFilesPath = Path.Combine(
project.DirectoryPath,
"build",
project.IntermediateOutputDirectory,
"compressed");
Assert.True(Directory.Exists(compressedFilesPath));
}
private static GenerateBlazorBootJson.BootJsonData ReadBootJsonData(MSBuildResult result, string path) private static GenerateBlazorBootJson.BootJsonData ReadBootJsonData(MSBuildResult result, string path)
{ {
return JsonSerializer.Deserialize<GenerateBlazorBootJson.BootJsonData>( return JsonSerializer.Deserialize<GenerateBlazorBootJson.BootJsonData>(

View File

@ -172,6 +172,20 @@ $@"<Project>
File.WriteAllText(ProjectFilePath, updated); File.WriteAllText(ProjectFilePath, updated);
} }
internal void AddDirectoryBuildContent(string content)
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
var filepath = Path.Combine(DirectoryPath, "Directory.Build.props");
var existing = File.ReadAllText(filepath);
var updated = existing.Replace("<!-- Test Placeholder -->", content);
File.WriteAllText(filepath, updated);
}
public void Dispose() public void Dispose()
{ {
if (PreserveWorkingDirectory) if (PreserveWorkingDirectory)

View File

@ -1,6 +1,8 @@
<Project> <Project>
<Import Project="Before.Directory.Build.props" Condition="Exists('Before.Directory.Build.props')" /> <Import Project="Before.Directory.Build.props" Condition="Exists('Before.Directory.Build.props')" />
<!-- Test Placeholder -->
<PropertyGroup> <PropertyGroup>
<RepoRoot Condition="'$(RepoRoot)' ==''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), global.json))\</RepoRoot> <RepoRoot Condition="'$(RepoRoot)' ==''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), global.json))\</RepoRoot>
<ComponentsRoot>$(RepoRoot)src\Components\</ComponentsRoot> <ComponentsRoot>$(RepoRoot)src\Components\</ComponentsRoot>