Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser] Override Wasm SDK pack in workload testing #85405

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageVersionNet7>7.0.5</PackageVersionNet7>
<PackageVersionNet6>6.0.$([MSBuild]::Add($([System.Version]::Parse('$(PackageVersionNet7)').Build),11))</PackageVersionNet6>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionIteration>4</PreReleaseVersionIteration>
<PreReleaseVersionIteration>5</PreReleaseVersionIteration>
<WorkloadVersionSuffix Condition="'$(PreReleaseVersionLabel)' != 'release'">-$(PreReleaseVersionLabel).$(PreReleaseVersionIteration)</WorkloadVersionSuffix>
<SdkBandVersionForWorkload_FromRuntimeVersions>$(SdkBandVersion)$(WorkloadVersionSuffix)</SdkBandVersionForWorkload_FromRuntimeVersions>
<!-- Set assembly version to align with major and minor version,
Expand Down
37 changes: 37 additions & 0 deletions src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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 +136,41 @@ public override bool Execute()
}
}

private static void ExtractWebAssemblySdkPack(string targetPath, string sourcePath)
{
string nupkg = Directory.EnumerateFiles(sourcePath, "Microsoft.NET.Sdk.WebAssembly.Pack.*.nupkg").Single();
if (Directory.Exists(targetPath))
Directory.Delete(targetPath, recursive: true);

Directory.CreateDirectory(targetPath);
System.IO.Compression.ZipFile.ExtractToDirectory(nupkg, targetPath);
}

private void OverrideWebAssemblySdkPack(string targetPath, string localNuGetsPath)
{
string packPath = Path.Combine(targetPath, "Microsoft.NET.Sdk.WebAssembly.Pack");
ExtractWebAssemblySdkPack(packPath, localNuGetsPath);

string propsPath = Directory.EnumerateFiles(targetPath, @"Sdk.props", SearchOption.AllDirectories).Single(f => f.Contains("Microsoft.NET.Sdk.WebAssembly"));
string targetsPath = Directory.EnumerateFiles(targetPath, @"Sdk.targets", SearchOption.AllDirectories).Single(f => f.Contains("Microsoft.NET.Sdk.WebAssembly"));

OverrideFile(propsPath, "$(_WebAssemblyPropsFile)", Path.Combine(packPath, "build", "Microsoft.NET.Sdk.WebAssembly.Browser.props"));
OverrideFile(targetsPath, "$(_WebAssemblyTargetsFile)", Path.Combine(packPath, "build", "Microsoft.NET.Sdk.WebAssembly.Browser.targets"));

void OverrideFile(string sdkFilePath, string propertyToReplace, string packAbsolutePath)
{
if (!File.Exists(sdkFilePath))
throw new FileNotFoundException(sdkFilePath);

if (!File.Exists(packAbsolutePath))
throw new FileNotFoundException(packAbsolutePath);

string packRelativePath = Path.GetRelativePath(Path.GetDirectoryName(sdkFilePath)!, packAbsolutePath);
File.WriteAllText(sdkFilePath, File.ReadAllText(sdkFilePath).Replace(propertyToReplace, "$(MSBuildThisFileDirectory)" + packRelativePath));
Log.LogMessage(MessageImportance.Low, $"Overriding WebAssembly SDK pack in {sdkFilePath} to point to {packRelativePath}");
}
}

private bool ExecuteInternal(InstallWorkloadRequest req)
{
if (!File.Exists(TemplateNuGetConfigPath))
Expand Down