Skip to content

Commit

Permalink
[wasm] Wasm.Build.Tests - Override KnownWebAssemblySdkPack to 8.0.0-d…
Browse files Browse the repository at this point in the history
…ev (#85815)
  • Loading branch information
maraf committed May 9, 2023
1 parent aaa1de1 commit a442971
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

Expand Down Expand Up @@ -117,6 +118,8 @@ public override bool Execute()
if (!ExecuteInternal(req) && !req.IgnoreErrors)
return false;

OverrideWebAssemblySdkPack(req.TargetPath, LocalNuGetsPath);

File.WriteAllText(req.StampPath, string.Empty);
}

Expand All @@ -134,6 +137,26 @@ public override bool Execute()
}
}

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))
Expand Down

0 comments on commit a442971

Please sign in to comment.