Skip to content

Commit a442971

Browse files
authored
[wasm] Wasm.Build.Tests - Override KnownWebAssemblySdkPack to 8.0.0-dev (#85815)
1 parent aaa1de1 commit a442971

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Linq;
1111
using System.Text.Json;
1212
using System.Text.Json.Serialization;
13+
using System.Xml.Linq;
1314
using Microsoft.Build.Framework;
1415
using Microsoft.Build.Utilities;
1516

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

121+
OverrideWebAssemblySdkPack(req.TargetPath, LocalNuGetsPath);
122+
120123
File.WriteAllText(req.StampPath, string.Empty);
121124
}
122125

@@ -134,6 +137,26 @@ public override bool Execute()
134137
}
135138
}
136139

140+
private static void OverrideWebAssemblySdkPack(string targetPath, string localNuGetsPath)
141+
{
142+
string nupkgName = "Microsoft.NET.Sdk.WebAssembly.Pack";
143+
string? nupkg = Directory.EnumerateFiles(localNuGetsPath, $"{nupkgName}.*.nupkg").FirstOrDefault();
144+
if (nupkg == null)
145+
return;
146+
147+
string nupkgVersion = Path.GetFileNameWithoutExtension(nupkg).Substring(nupkgName.Length + 1);
148+
149+
string bundledVersions = Directory.EnumerateFiles(targetPath, @"Microsoft.NETCoreSdk.BundledVersions.props", SearchOption.AllDirectories).Single();
150+
var document = XDocument.Load(bundledVersions);
151+
if (document != null)
152+
{
153+
foreach (var element in document.Descendants("KnownWebAssemblySdkPack"))
154+
element.SetAttributeValue("WebAssemblySdkPackVersion", nupkgVersion);
155+
156+
document.Save(bundledVersions);
157+
}
158+
}
159+
137160
private bool ExecuteInternal(InstallWorkloadRequest req)
138161
{
139162
if (!File.Exists(TemplateNuGetConfigPath))

0 commit comments

Comments
 (0)