Fix treating dotnet.wasm or dotnet.native.wasm as native asset (#89079)
authorMarek Fišera <mara@neptuo.com>
Tue, 18 Jul 2023 17:02:16 +0000 (19:02 +0200)
committerGitHub <noreply@github.com>
Tue, 18 Jul 2023 17:02:16 +0000 (19:02 +0200)
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs

index 0a9521f..df269f5 100644 (file)
@@ -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 @@ public class ComputeWasmPublishAssets : Task
 
                 ApplyPublishProperties(newDotNetWasm);
                 nativeStaticWebAssets.Add(newDotNetWasm);
+
                 if (resolvedNativeAssetToPublish.TryGetValue("dotnet.native.wasm", out var resolved))
                 {
                     filesToRemove.Add(resolved);
@@ -592,7 +591,14 @@ public class ComputeWasmPublishAssets : Task
                 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");
@@ -644,6 +650,12 @@ public class ComputeWasmPublishAssets : Task
             // upgraded
             if (string.Equals(candidate.GetMetadata("AssetType"), "native", StringComparison.Ordinal))
             {
+                ResolveAsNativeAsset(Log, resolvedNativeAssetToPublish, candidate, extension);
+                continue;
+            }
+
+            static void ResolveAsNativeAsset(TaskLoggingHelper log, Dictionary<string, ITaskItem> resolvedNativeAssetToPublish, ITaskItem candidate, string extension)
+            {
                 var candidateName = $"{candidate.GetMetadata("FileName")}{extension}";
                 if (!resolvedNativeAssetToPublish.ContainsKey(candidateName))
                 {
@@ -651,9 +663,8 @@ public class ComputeWasmPublishAssets : Task
                 }
                 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
         }