From 00e1d67e4b1f41162f19d07dd35e78f0722dc00f Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Thu, 14 Dec 2023 21:27:28 -0500 Subject: [PATCH 1/4] [wasm] Browser.targets: Fix .dlls being deployed to `publish/` IL-linked dlls get copied to the `publish/` directory when using AOT. This is because in `ProcessPublishFilesForWasm` target the `ResolvedFileToPublish` item ends with a copy of the original .dll files, even though they should be replaced with what was received from the nested publish. --- .../Microsoft.NET.Sdk.WebAssembly.Browser.targets | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 13a8719e62240c..f5b49c75cc3025 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -23,7 +23,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_RunWorkingDirectory>$(OutputPath) <_RunWorkingDirectory Condition="'$(_RunWorkingDirectory)' != '' and !$([System.IO.Path]::IsPathRooted($(_RunWorkingDirectory)))">$([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(_RunWorkingDirectory))) <_RuntimeConfigJsonPath>$([MSBuild]::NormalizePath($(_RunWorkingDirectory), '$(AssemblyName).runtimeconfig.json')) - + exec "$([MSBuild]::NormalizePath($(WasmAppHostDir), 'WasmAppHost.dll'))" --use-staticwebassets --runtime-config "$(_RuntimeConfigJsonPath)" $(WasmHostArguments) $(_RunWorkingDirectory) @@ -395,7 +395,7 @@ Copyright (c) .NET Foundation. All rights reserved. BeforeTargets="PrepareForPublish" /> - + + + <_WasmResolvedFilesToPublish Include="@(ResolvedFileToPublish)" /> + From 7acfc2ea7f81fabd8b697f4ba8838e1fca6dd2ca Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 18 Dec 2023 17:07:21 -0500 Subject: [PATCH 2/4] add tests --- .../wasm/Wasm.Build.Tests/ProjectProviderBase.cs | 2 +- .../Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index b1b6a031be38e9..50dac9c67a1e7a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -33,7 +33,7 @@ public abstract class ProjectProviderBase(ITestOutputHelper _testOutput, string? }; public string? ProjectDir { get; set; } = _projectDir; - protected ITestOutputHelper _testOutput = _testOutput; + protected ITestOutputHelper _testOutput = new TestOutputWrapper(_testOutput); protected BuildEnvironment _buildEnv = BuildTestBase.s_buildEnv; public string BundleDirName { get; set; } = "wwwroot"; diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs b/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs index 9ff2155c68e600..0480473d249a68 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Collections.Generic; +using Xunit; using Xunit.Abstractions; using Xunit.Sdk; using System.Linq; @@ -76,6 +77,18 @@ public void AssertBundle(AssertWasmSdkBundleOptions assertOptions) { IReadOnlyDictionary actualDotnetFiles = AssertBasicBundle(assertOptions); + if (assertOptions.IsPublish) + { + string publishPath = Path.GetFullPath(Path.Combine(assertOptions.BinFrameworkDir, "..", "..")); + Assert.Equal("publish", Path.GetFileName(publishPath)); + + var dlls = Directory.EnumerateFiles(publishPath, "*.dll"); + Assert.False(dlls.Any(), $"Did not expect to find any .dll in {publishPath} but found {string.Join(",", dlls)}"); + + var wasmAssemblies = Directory.EnumerateFiles(publishPath, "*.wasm"); + Assert.False(wasmAssemblies.Any(), $"Did not expect to find any .wasm files in {publishPath} but found {string.Join(",", wasmAssemblies)}"); + } + if (!BuildTestBase.IsUsingWorkloads) return; From 311383002b55e7aca08ade0431de15953902c079 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 18 Dec 2023 17:08:07 -0500 Subject: [PATCH 3/4] InstallWorkloadFromArtifacts: default to using obj dir as temp, to get better behavior with anti-viruses --- eng/testing/workloads-testing.targets | 1 + src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/eng/testing/workloads-testing.targets b/eng/testing/workloads-testing.targets index 910ce227dd6887..5c4e021e7a8849 100644 --- a/eng/testing/workloads-testing.targets +++ b/eng/testing/workloads-testing.targets @@ -211,6 +211,7 @@ LocalNuGetsPath="$(LibrariesShippingPackagesDir)" TemplateNuGetConfigPath="$(RepoRoot)NuGet.config" SdkWithNoWorkloadInstalledPath="$(_SdkWithNoWorkloadPath)" + IntermediateOutputPath="$(ArtifactsObjDir)wasm" /> diff --git a/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs b/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs index c43b416dc67c78..0ed03bd4db6dc6 100644 --- a/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs +++ b/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs @@ -42,6 +42,7 @@ public partial class InstallWorkloadFromArtifacts : Task [Required, NotNull] public string SdkWithNoWorkloadInstalledPath { get; set; } = string.Empty; + public string? IntermediateOutputPath { get; set; } public bool OnlyUpdateManifests{ get; set; } private const string s_nugetInsertionTag = ""; @@ -59,7 +60,7 @@ public partial class InstallWorkloadFromArtifacts : Task public override bool Execute() { - _tempDir = Path.Combine(Path.GetTempPath(), $"workload-{Path.GetRandomFileName()}"); + _tempDir = Path.Combine(IntermediateOutputPath ?? Path.GetTempPath(), $"workload-{Path.GetRandomFileName()}"); if (Directory.Exists(_tempDir)) Directory.Delete(_tempDir, recursive: true); Directory.CreateDirectory(_tempDir); From af9344e095fa777155cbaac4574f2c7f06e919e8 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 18 Dec 2023 17:08:27 -0500 Subject: [PATCH 4/4] cleanup --- src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 9378c052e076ec..e7be07f71c89e1 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -155,11 +155,11 @@ public void DefaultTemplate_WithResources_Publish(string config) if (config == "Release") { // relinking in publish for Release config - BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked, ExpectRelinkDirWhenPublishing: true)); + BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked, ExpectRelinkDirWhenPublishing: true, IsPublish: true)); } else { - BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack, ExpectRelinkDirWhenPublishing: true)); + BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack, ExpectRelinkDirWhenPublishing: true, IsPublish: true)); } AssertResourcesDlls(FindBlazorBinFrameworkDir(config, true));