From c2cf1380bbaec9fce6e9e3eee6ff90f7768fd5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 18 Jul 2023 15:05:42 +0200 Subject: [PATCH] Fix treating dotnet.wasm or dotnet.native.wasm as native asset --- .../ComputeWasmPublishAssets.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs index 0a9521f9b2795..df269f565e1d7 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs @@ -3,12 +3,10 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; -using Microsoft.NET.Sdk.WebAssembly; namespace Microsoft.NET.Sdk.WebAssembly; @@ -265,6 +263,7 @@ private List ProcessNativeAssets( ApplyPublishProperties(newDotNetWasm); nativeStaticWebAssets.Add(newDotNetWasm); + if (resolvedNativeAssetToPublish.TryGetValue("dotnet.native.wasm", out var resolved)) { filesToRemove.Add(resolved); @@ -592,7 +591,14 @@ private void GroupResolvedFilesToPublish( continue; } + var fileName = candidate.GetMetadata("FileName"); var extension = candidate.GetMetadata("Extension"); + if (string.Equals(candidate.GetMetadata("AssetType"), "native", StringComparison.Ordinal) && (fileName == "dotnet" || fileName == "dotnet.native") && extension == ".wasm") + { + ResolveAsNativeAsset(Log, resolvedNativeAssetToPublish, candidate, extension); + continue; + } + if (string.Equals(extension, ".dll", StringComparison.Ordinal) || string.Equals(extension, Utils.WebcilInWasmExtension, StringComparison.Ordinal)) { var culture = candidate.GetMetadata("Culture"); @@ -643,6 +649,12 @@ private void GroupResolvedFilesToPublish( // Capture all the native unfiltered assets since we need to process them to determine what static web assets need to get // upgraded if (string.Equals(candidate.GetMetadata("AssetType"), "native", StringComparison.Ordinal)) + { + ResolveAsNativeAsset(Log, resolvedNativeAssetToPublish, candidate, extension); + continue; + } + + static void ResolveAsNativeAsset(TaskLoggingHelper log, Dictionary resolvedNativeAssetToPublish, ITaskItem candidate, string extension) { var candidateName = $"{candidate.GetMetadata("FileName")}{extension}"; if (!resolvedNativeAssetToPublish.ContainsKey(candidateName)) @@ -651,9 +663,8 @@ private void GroupResolvedFilesToPublish( } else { - Log.LogMessage(MessageImportance.Low, "Duplicate candidate '{0}' found in ResolvedFilesToPublish", candidate.ItemSpec); + log.LogMessage(MessageImportance.Low, "Duplicate candidate '{0}' found in ResolvedFilesToPublish", candidate.ItemSpec); } - continue; } #pragma warning restore CA1864 }