From 1b67eefe8a530b302028b54e245fb402191b544e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Fri, 15 Nov 2024 13:11:12 +0000 Subject: [PATCH] Fix updating KnownWebAssemblySdkPack when creating test layout We missed adding KnownWebAssemblySdkPack into OverrideAndCreateBundledNETCoreAppPackageVersion so it was pointing to an older version in the BundledVersion.props in the test layout. Fix that and add some checks so we don't miss this again the next time we add a Known*Pack entry. Fixes https://github.com/dotnet/sdk/issues/44886 --- ...ndCreateBundledNETCoreAppPackageVersion.cs | 37 ++++++++++++------- ...T.WindowsSdkSupportedTargetPlatforms.props | 4 +- .../BlazorLegacyIntegrationTest60.cs | 6 +-- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs index 7afddc804509..c6e62d181b97 100644 --- a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs +++ b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs @@ -9,7 +9,7 @@ namespace Microsoft.DotNet.Build.Tasks /// /// Use the runtime in dotnet/sdk instead of in the stage 0 to avoid circular dependency. /// If there is a change depended on the latest runtime. Without override the runtime version in BundledNETCoreAppPackageVersion - /// we would need to somehow get this change in without the test, and then insertion dotnet/installer + /// we would need to somehow get this change in without the test, and then insertion dotnet/sdk /// and then update the stage 0 back. /// /// Override NETCoreSdkVersion to stage 0 sdk version like 6.0.100-dev @@ -21,7 +21,7 @@ public sealed class OverrideAndCreateBundledNETCoreAppPackageVersion : Task { private static string _messageWhenMismatch = "{0} version {1} does not match BundledNETCoreAppPackageVersion {2}. " + - "The schema of https://github.com/dotnet/installer/blob/main/src/redist/targets/GenerateBundledVersions.targets might change. " + + "The schema of https://github.com/dotnet/sdk/blob/main/src/Installer/redist-installer/targets/GenerateBundledVersions.targets might change. " + "We need to ensure we can swap the runtime version from what's in stage0 to what dotnet/sdk used successfully"; [Required] public string Stage0MicrosoftNETCoreAppRefPackageVersionPath { get; set; } @@ -51,7 +51,7 @@ public static string ExecuteInternal( var ns = projectXml.Root.Name.Namespace; - var propertyGroup = projectXml.Root.Elements(ns + "PropertyGroup").First(); + var propertyGroup = projectXml.Root.Elements(ns + "PropertyGroup").First(); propertyGroup.Element(ns + "NETCoreSdkVersion").Value = newSDKVersion; @@ -118,17 +118,28 @@ void CheckAndReplaceAttribute(XAttribute attribute) CheckAndReplaceAttribute(itemGroup .Elements(ns + "KnownFrameworkReference").First().Attribute("LatestRuntimeFrameworkVersion")); - CheckAndReplaceAttribute(itemGroup - .Elements(ns + "KnownAppHostPack").First().Attribute("AppHostPackVersion")); - CheckAndReplaceAttribute(itemGroup - .Elements(ns + "KnownCrossgen2Pack").First().Attribute("Crossgen2PackVersion")); - CheckAndReplaceAttribute(itemGroup - .Elements(ns + "KnownILCompilerPack").First().Attribute("ILCompilerPackVersion")); - CheckAndReplaceAttribute(itemGroup - .Elements(ns + "KnownILLinkPack").First().Attribute("ILLinkPackVersion")); - CheckAndReplaceAttribute(itemGroup - .Elements(ns + "KnownRuntimePack").First().Attribute("LatestRuntimeFrameworkVersion")); + (string Name, string VersionAttribute)[] knownPacksAndVersionAttribute = { + ("KnownAppHostPack", "AppHostPackVersion"), + ("KnownCrossgen2Pack", "Crossgen2PackVersion"), + ("KnownILCompilerPack", "ILCompilerPackVersion"), + ("KnownILLinkPack", "ILLinkPackVersion"), + ("KnownWebAssemblySdkPack", "WebAssemblySdkPackVersion"), + ("KnownRuntimePack", "LatestRuntimeFrameworkVersion"), + }; + + // update all Known*Pack elements + foreach (var item in knownPacksAndVersionAttribute) + { + CheckAndReplaceAttribute(itemGroup.Elements(ns + item.Name).First().Attribute(item.VersionAttribute)); + } + + // check that we didn't miss any Known*Pack elements + foreach (var item in itemGroup.Elements().Where(i => i.Name.LocalName.StartsWith("Known") && i.Name.LocalName.EndsWith("Pack"))) + { + if (!knownPacksAndVersionAttribute.Any(p => p.Name == item.Name.LocalName)) + throw new InvalidOperationException($"Unexpected Known*Pack element: {item.Name.LocalName}"); + } return projectXml.ToString(); } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.WindowsSdkSupportedTargetPlatforms.props b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.WindowsSdkSupportedTargetPlatforms.props index 34439118b427..c58bd9f81576 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.WindowsSdkSupportedTargetPlatforms.props +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.WindowsSdkSupportedTargetPlatforms.props @@ -12,8 +12,8 @@ Copyright (c) .NET Foundation. All rights reserved. - - + + diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest60.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest60.cs index 0602e895315e..989fc82a59fe 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest60.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest60.cs @@ -10,12 +10,12 @@ public class BlazorLegacyIntegrationTest60(ITestOutputHelper log) : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(BlazorLegacyIntegrationTest60)) { - protected override string EmbeddedResourcePrefix => + protected override string EmbeddedResourcePrefix => string.Join('.', "Microsoft.NET.Sdk.BlazorWebAssembly.Tests", "StaticWebAssetsBaselines"); protected override string ComputeBaselineFolder() => Path.Combine(TestContext.GetRepoRoot() ?? AppContext.BaseDirectory, "test", "Microsoft.NET.Sdk.BlazorWebAssembly.Tests", "StaticWebAssetsBaselines"); - + [CoreMSBuildOnlyFact] public void Build60Hosted_Works() { @@ -44,7 +44,7 @@ public void Build60Hosted_Works() new FileInfo(Path.Combine(serverBuildOutputDirectory, $"{testAsset}.Shared.dll")).Should().Exist(); } - [WindowsOnlyRequiresMSBuildVersionFact("17.13", Reason = "Needs System.Text.Json 8.0.5")] // https://github.com/dotnet/sdk/issues/44886 + [Fact] [SkipOnPlatform(TestPlatforms.Linux | TestPlatforms.OSX, "https://github.com/dotnet/sdk/issues/42145")] public void Publish60Hosted_Works() {