Preserve files being published to the publish root and the wwwroot (#19938)
* Preserve files being published to the publish root and the wwwroot Fixes https://github.com/dotnet/aspnetcore/issues/19926
This commit is contained in:
commit
b906b1033c
|
|
@ -1,3 +1,7 @@
|
|||
<Project>
|
||||
<Import Project="$(MSBuildThisFileDirectory)..\..\targets\All.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<ReferencesComponentsWebAssemblyBuild>true</ReferencesComponentsWebAssemblyBuild>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -272,6 +272,15 @@
|
|||
<ReadLinesFromFile File="$(_BlazorApplicationAssembliesCacheFile)" Condition="'@(_BlazorResolvedAssembly->Count())' == '0'">
|
||||
<Output TaskParameter="Lines" ItemName="_BlazorResolvedAssembly"/>
|
||||
</ReadLinesFromFile>
|
||||
|
||||
<ItemGroup>
|
||||
<!--
|
||||
Workaround for https://github.com/dotnet/aspnetcore/issues/19926. Add _BlazorResolvedAssembly to FileWrites so that these files
|
||||
do not get removed during an incremental build. Note that we add these files here as opposed to _ResolveBlazorRuntimeDependencies
|
||||
since the task that calculates these items in _ResolveBlazorRuntimeDependencies does not execute in incremental builds.
|
||||
-->
|
||||
<FileWrites Include="$(_BlazorResolvedAssembly)"/>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<Target
|
||||
|
|
@ -291,9 +300,20 @@
|
|||
ApplicationDependencies="@(_BlazorManagedRuntimeAssembly)"
|
||||
WebAssemblyBCLAssemblies="@(_WebAssemblyBCLAssembly)">
|
||||
|
||||
<Output TaskParameter="Dependencies" ItemName="_BlazorResolvedAssembly" />
|
||||
<Output TaskParameter="Dependencies" ItemName="_BlazorResolvedAssemblyUnlinked" />
|
||||
</ResolveBlazorRuntimeDependencies>
|
||||
|
||||
<!--
|
||||
Workaround for https://github.com/dotnet/aspnetcore/issues/19926. Using the files from their initial locations
|
||||
as-is causes RazorSDK to remove files from a hosted app's publish directory. This is because files being removed
|
||||
are looked up by their path. We'll copy files to an intermediate location to avoid the removal code.
|
||||
-->
|
||||
<Copy
|
||||
SourceFiles="@(_BlazorResolvedAssemblyUnlinked)"
|
||||
DestinationFolder="$(_BlazorIntermediateOutputPath)unlinked">
|
||||
<Output TaskParameter="CopiedFiles" ItemName="_BlazorResolvedAssembly" />
|
||||
</Copy>
|
||||
|
||||
<WriteLinesToFile File="$(_BlazorApplicationAssembliesCacheFile)" Lines="@(_BlazorResolvedAssembly)" Overwrite="true" />
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -178,18 +178,23 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_HostedApp_Works()
|
||||
public async Task Publish_HostedApp_WithLinkOnBuildTrue_Works()
|
||||
{
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("blazorhosted", additionalProjects: new[] { "standalone", "razorclasslibrary", });
|
||||
project.TargetFramework = "netcoreapp3.1";
|
||||
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
|
||||
AddSiblingProjectFileContent(project, @"
|
||||
<PropertyGroup>
|
||||
<BlazorWebAssemblyEnableLinking>true</BlazorWebAssemblyEnableLinking>
|
||||
</PropertyGroup>");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
var publishDirectory = project.PublishOutputDirectory;
|
||||
// Make sure the main project exists
|
||||
Assert.FileExists(result, publishDirectory, "blazorhosted.dll");
|
||||
Assert.FileExists(result, publishDirectory, "RazorClassLibrary.dll");
|
||||
|
||||
var blazorPublishDirectory = Path.Combine(publishDirectory, "wwwroot");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
|
||||
|
|
@ -198,6 +203,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "wasm", DotNetJsFileName);
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "_bin", "standalone.dll");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "_bin", "Microsoft.Extensions.Logging.Abstractions.dll"); // Verify dependencies are part of the output.
|
||||
// Verify project references appear as static web assets
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "_bin", "RazorClassLibrary.dll");
|
||||
// Also verify project references to the server project appear in the publish output
|
||||
Assert.FileExists(result, publishDirectory, "RazorClassLibrary.dll");
|
||||
|
||||
// Verify static assets are in the publish directory
|
||||
Assert.FileExists(result, blazorPublishDirectory, "index.html");
|
||||
|
|
@ -224,7 +233,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
using var project = ProjectDirectory.Create("blazorhosted", additionalProjects: new[] { "standalone", "razorclasslibrary", });
|
||||
project.TargetFramework = "netcoreapp3.1";
|
||||
|
||||
AddSiblingProjectFileContent(@"
|
||||
AddSiblingProjectFileContent(project, @"
|
||||
<PropertyGroup>
|
||||
<BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking>
|
||||
</PropertyGroup>");
|
||||
|
|
@ -241,12 +250,18 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
// Make sure the main project exists
|
||||
Assert.FileExists(result, publishDirectory, "blazorhosted.dll");
|
||||
|
||||
// Verification for https://github.com/dotnet/aspnetcore/issues/19926. Verify binaries for projects
|
||||
// referenced by the Hosted project appear in the publish directory
|
||||
Assert.FileExists(result, publishDirectory, "RazorClassLibrary.dll");
|
||||
Assert.FileExists(result, publishDirectory, "standalone.dll");
|
||||
|
||||
var blazorPublishDirectory = Path.Combine(publishDirectory, "wwwroot");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.webassembly.js");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "wasm", "dotnet.wasm");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "wasm", DotNetJsFileName);
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "_bin", "standalone.dll");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "_bin", "RazorClassLibrary.dll");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "_framework", "_bin", "Microsoft.Extensions.Logging.Abstractions.dll"); // Verify dependencies are part of the output.
|
||||
|
||||
// Verify static assets are in the publish directory
|
||||
|
|
@ -268,14 +283,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
serviceWorkerContent: "// This is the production service worker",
|
||||
assetsManifestPath: "custom-service-worker-assets.js");
|
||||
|
||||
void AddSiblingProjectFileContent(string content)
|
||||
{
|
||||
var path = Path.Combine(project.SolutionPath, "standalone", "standalone.csproj");
|
||||
var existing = File.ReadAllText(path);
|
||||
var updated = existing.Replace("<!-- Test Placeholder -->", content);
|
||||
File.WriteAllText(path, updated);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_HostedApp_WithNoBuild_Works()
|
||||
|
|
@ -319,6 +327,14 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
assetsManifestPath: "custom-service-worker-assets.js");
|
||||
}
|
||||
|
||||
private static void AddSiblingProjectFileContent(ProjectDirectory project, string content)
|
||||
{
|
||||
var path = Path.Combine(project.SolutionPath, "standalone", "standalone.csproj");
|
||||
var existing = File.ReadAllText(path);
|
||||
var updated = existing.Replace("<!-- Test Placeholder -->", content);
|
||||
File.WriteAllText(path, updated);
|
||||
}
|
||||
|
||||
private static void VerifyBootManifestHashes(MSBuildResult result, string blazorPublishDirectory)
|
||||
{
|
||||
var bootManifestResolvedPath = Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ namespace blazorhosted.Server
|
|||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(typeof(IWebHost));
|
||||
GC.KeepAlive(typeof(RazorClassLibrary.Class1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue