using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
+using System.Xml.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
if (!ExecuteInternal(req) && !req.IgnoreErrors)
return false;
+ OverrideWebAssemblySdkPack(req.TargetPath, LocalNuGetsPath);
+
File.WriteAllText(req.StampPath, string.Empty);
}
}
}
+ 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))