[wasm] Wasm.Build.Tests - Override KnownWebAssemblySdkPack to 8.0.0-dev (#85815)
authorMarek Fišera <mara@neptuo.com>
Tue, 9 May 2023 09:55:32 +0000 (11:55 +0200)
committerGitHub <noreply@github.com>
Tue, 9 May 2023 09:55:32 +0000 (11:55 +0200)
src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs

index b32be966245293a999fcfb58cd94a4c84c73dd8a..9d16bf5d10b01e7a86da0ffbc6a33c64f06ab079 100644 (file)
@@ -10,6 +10,7 @@ using System.IO.Compression;
 using System.Linq;
 using System.Text.Json;
 using System.Text.Json.Serialization;
+using System.Xml.Linq;
 using Microsoft.Build.Framework;
 using Microsoft.Build.Utilities;
 
@@ -117,6 +118,8 @@ namespace Microsoft.Workload.Build.Tasks
                     if (!ExecuteInternal(req) && !req.IgnoreErrors)
                         return false;
 
+                    OverrideWebAssemblySdkPack(req.TargetPath, LocalNuGetsPath);
+
                     File.WriteAllText(req.StampPath, string.Empty);
                 }
 
@@ -134,6 +137,26 @@ namespace Microsoft.Workload.Build.Tasks
             }
         }
 
+        private static void OverrideWebAssemblySdkPack(string targetPath, string localNuGetsPath)
+        {
+            string nupkgName = "Microsoft.NET.Sdk.WebAssembly.Pack";
+            string? nupkg = Directory.EnumerateFiles(localNuGetsPath, $"{nupkgName}.*.nupkg").FirstOrDefault();
+            if (nupkg == null)
+                return;
+
+            string nupkgVersion = Path.GetFileNameWithoutExtension(nupkg).Substring(nupkgName.Length + 1);
+
+            string bundledVersions = Directory.EnumerateFiles(targetPath, @"Microsoft.NETCoreSdk.BundledVersions.props", SearchOption.AllDirectories).Single();
+            var document = XDocument.Load(bundledVersions);
+            if (document != null)
+            {
+                foreach (var element in document.Descendants("KnownWebAssemblySdkPack"))
+                    element.SetAttributeValue("WebAssemblySdkPackVersion", nupkgVersion);
+
+                document.Save(bundledVersions);
+            }
+        }
+
         private bool ExecuteInternal(InstallWorkloadRequest req)
         {
             if (!File.Exists(TemplateNuGetConfigPath))