Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] Browser.targets: Fix .dlls being deployed to publish/ #96045

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/testing/workloads-testing.targets
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
LocalNuGetsPath="$(LibrariesShippingPackagesDir)"
TemplateNuGetConfigPath="$(RepoRoot)NuGet.config"
SdkWithNoWorkloadInstalledPath="$(_SdkWithNoWorkloadPath)"
IntermediateOutputPath="$(ArtifactsObjDir)wasm"
/>

<Touch Files="$(_SdkWithNoWorkloadStampPath)" AlwaysCreate="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<_RunWorkingDirectory>$(OutputPath)</_RunWorkingDirectory>
<_RunWorkingDirectory Condition="'$(_RunWorkingDirectory)' != '' and !$([System.IO.Path]::IsPathRooted($(_RunWorkingDirectory)))">$([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(_RunWorkingDirectory)))</_RunWorkingDirectory>
<_RuntimeConfigJsonPath>$([MSBuild]::NormalizePath($(_RunWorkingDirectory), '$(AssemblyName).runtimeconfig.json'))</_RuntimeConfigJsonPath>

<RunArguments>exec &quot;$([MSBuild]::NormalizePath($(WasmAppHostDir), 'WasmAppHost.dll'))&quot; --use-staticwebassets --runtime-config &quot;$(_RuntimeConfigJsonPath)&quot; $(WasmHostArguments)</RunArguments>
<RunWorkingDirectory>$(_RunWorkingDirectory)</RunWorkingDirectory>
</PropertyGroup>
Expand Down Expand Up @@ -395,7 +395,7 @@ Copyright (c) .NET Foundation. All rights reserved.
BeforeTargets="PrepareForPublish" />

<!-- Wasm's Nested publish is run just to build the native bits. We don't need to run blazor targets for that -->
<Target Name="ProcessPublishFilesForWasm" DependsOnTargets="_ResolveWasmConfiguration;LoadStaticWebAssetsBuildManifest;_GetWasmRuntimePackVersion" AfterTargets="ILLink" Condition="'$(WasmBuildingForNestedPublish)' != 'true'">
<Target Name="ProcessPublishFilesForWasm" DependsOnTargets="_ResolveWasmConfiguration;LoadStaticWebAssetsBuildManifest;_GetWasmRuntimePackVersion;_GatherWasmFilesToPublish" AfterTargets="ILLink" Condition="'$(WasmBuildingForNestedPublish)' != 'true'">
<!-- The list of static web assets already contains all the assets from the build. We want to correct certain assets that might
have changed as part of the publish process. We are going to do so as follows:
* We will update Blazor runtime asset dlls if we are running PublishTrimmed
Expand All @@ -419,7 +419,10 @@ Copyright (c) .NET Foundation. All rights reserved.
</ItemGroup>
<ItemGroup Condition="@(WasmAssembliesFinal->Count()) > 0">
<_WasmResolvedFilesToPublish Include="@(WasmAssembliesFinal)" />
<_WasmResolvedFilesToPublish Include="@(ResolvedFileToPublish)" Condition="'%(Extension)' != '.dll'" />

<!-- remove the original assemblies -->
<ResolvedFileToPublish Remove="@(WasmAssembliesToBundle)" />
<_WasmResolvedFilesToPublish Include="@(ResolvedFileToPublish)" />
</ItemGroup>

<ComputeWasmPublishAssets
Expand Down Expand Up @@ -600,6 +603,7 @@ Copyright (c) .NET Foundation. All rights reserved.
Code="BLAZORSDK1002" />
</Target>

<!-- called twice, once in the regular publish, and the other in the nested publish -->
<Target Name="_GatherWasmFilesToPublish">
<ItemGroup>
<WasmAssembliesToBundle Remove="@(WasmAssembliesToBundle)" />
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
13 changes: 13 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
using System.Linq;
Expand Down Expand Up @@ -76,6 +77,18 @@ public void AssertBundle(AssertWasmSdkBundleOptions assertOptions)
{
IReadOnlyDictionary<string, DotNetFileName> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<!-- TEST_RESTORE_SOURCES_INSERTION_LINE -->";
Expand All @@ -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);
Expand Down