From 24ffef06599e50fecdebfcb1410bcb703bead05b Mon Sep 17 00:00:00 2001 From: William Li Date: Thu, 16 Jan 2020 13:13:19 -0800 Subject: [PATCH 1/5] Remove -gg in harvest --- src/redist/targets/packaging/windows/clisdk/generatemsi.ps1 | 2 +- .../targets/packaging/windows/clisdk/generatetemplatesmsi.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/redist/targets/packaging/windows/clisdk/generatemsi.ps1 b/src/redist/targets/packaging/windows/clisdk/generatemsi.ps1 index d19137f5c..3920119b3 100644 --- a/src/redist/targets/packaging/windows/clisdk/generatemsi.ps1 +++ b/src/redist/targets/packaging/windows/clisdk/generatemsi.ps1 @@ -31,7 +31,7 @@ function RunHeat # use XSLT tranform to match the file path contains "AppHostTemplate\apphost.exe" and give it the same ID all the time. $heatOutput = .\heat.exe dir `"$inputDir`" -template fragment ` - -sreg -gg ` + -sreg -ag ` -var var.DotnetSrc ` -cg InstallFiles ` -srd ` diff --git a/src/redist/targets/packaging/windows/clisdk/generatetemplatesmsi.ps1 b/src/redist/targets/packaging/windows/clisdk/generatetemplatesmsi.ps1 index a987c584c..7947d20a4 100644 --- a/src/redist/targets/packaging/windows/clisdk/generatetemplatesmsi.ps1 +++ b/src/redist/targets/packaging/windows/clisdk/generatetemplatesmsi.ps1 @@ -25,7 +25,7 @@ function RunHeat Write-Information "Running heat.." $heatOutput = .\heat.exe dir `"$inputDir`" -template fragment ` - -sreg -gg ` + -sreg -ag ` -var var.DotnetSrc ` -cg InstallFiles ` -srd ` From b76a641e4fb54308101fcda03f49753c6ca10915 Mon Sep 17 00:00:00 2001 From: William Li Date: Sat, 25 Jan 2020 11:17:32 -0800 Subject: [PATCH 2/5] Use Task to calculate template versions No behaivor change --- Microsoft.DotNet.Cli.sln | 7 ++ .../CalculateTemplateVersions.cs | 84 +++++++++++++++++++ src/redist/targets/BuildCoreSdkTasks.targets | 1 + src/redist/targets/BundledTemplates.targets | 67 +++++++-------- .../CalculateTemplateVerionsTests.cs | 27 ++++++ .../core-sdk-tasks.Tests.csproj | 14 ++++ 6 files changed, 162 insertions(+), 38 deletions(-) create mode 100644 src/core-sdk-tasks/CalculateTemplateVersions.cs create mode 100644 test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs create mode 100644 test/core-sdk-tasks.Tests/core-sdk-tasks.Tests.csproj diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index a5f56ff79..22d771abd 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Dotnet.Sdk.Intern EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SdkTests", "test\SdkTests\SdkTests.csproj", "{CB1EE94E-CB83-4071-9DD0-9929AE2B7282}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "core-sdk-tasks.Tests", "test\core-sdk-tasks.Tests\core-sdk-tasks.Tests.csproj", "{658EF9BE-452C-4D31-AA24-B9E2235799A8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +57,10 @@ Global {CB1EE94E-CB83-4071-9DD0-9929AE2B7282}.Debug|Any CPU.Build.0 = Debug|Any CPU {CB1EE94E-CB83-4071-9DD0-9929AE2B7282}.Release|Any CPU.ActiveCfg = Release|Any CPU {CB1EE94E-CB83-4071-9DD0-9929AE2B7282}.Release|Any CPU.Build.0 = Release|Any CPU + {658EF9BE-452C-4D31-AA24-B9E2235799A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {658EF9BE-452C-4D31-AA24-B9E2235799A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {658EF9BE-452C-4D31-AA24-B9E2235799A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {658EF9BE-452C-4D31-AA24-B9E2235799A8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -66,6 +72,7 @@ Global {78E15EC1-7732-41E3-8591-934E9F583254} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {7EE15292-2CAD-44FA-8A1F-BAC4688A49E0} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {CB1EE94E-CB83-4071-9DD0-9929AE2B7282} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} + {658EF9BE-452C-4D31-AA24-B9E2235799A8} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B526D2CE-EE2D-4AD4-93EF-1867D90FF1F5} diff --git a/src/core-sdk-tasks/CalculateTemplateVersions.cs b/src/core-sdk-tasks/CalculateTemplateVersions.cs new file mode 100644 index 000000000..7d02618d3 --- /dev/null +++ b/src/core-sdk-tasks/CalculateTemplateVersions.cs @@ -0,0 +1,84 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Microsoft.DotNet.Cli.Build +{ + public class CalculateTemplateVersions : Task + { + [Required] + public string AspNetCorePackageVersionTemplate { get; set; } + + [Required] + public string GitCommitCount { get; set; } + + [Required] + public string VersionSuffix { get; set; } + + [Output] + public string BundledTemplateMSIVersion { get; set; } + + [Output] + public string BundledTemplateInstallPath { get; set; } + + [Output] + public string BundledTemplateMajorMinorVersion { get; set; } + + public override bool Execute() + { + var result = Calculate(AspNetCorePackageVersionTemplate, GitCommitCount, VersionSuffix); + BundledTemplateMSIVersion = result.BundledTemplateMsiVersion; + BundledTemplateInstallPath = result.BundledTemplateInstallPath; + BundledTemplateMajorMinorVersion = result.BundledTemplateMajorMinorVersion; + + return true; + } + + public static + (string BundledTemplateMsiVersion, + string BundledTemplateInstallPath, + string BundledTemplateMajorMinorVersion) Calculate(string aspNetCorePackageVersionTemplate, + string gitCommitCount, string versionSuffix) + { + (bool isStableVersion, string aspNetCoreVersionMajorMinorPatchVersion) = + GetAspNetCoreVersionMajorMinorPatchVersion(aspNetCorePackageVersionTemplate); + + var bundledTemplateMsiVersion = $"{aspNetCoreVersionMajorMinorPatchVersion}.{gitCommitCount}"; + + string bundledTemplateInstallPath = isStableVersion + ? aspNetCoreVersionMajorMinorPatchVersion + : $"{aspNetCoreVersionMajorMinorPatchVersion}-{versionSuffix}"; + + var parsedAspNetCoreVersionMajorMinorPatchVersion = + System.Version.Parse(aspNetCoreVersionMajorMinorPatchVersion); + var bundledTemplateMajorMinorVersion = + $"{parsedAspNetCoreVersionMajorMinorPatchVersion.Major}.{parsedAspNetCoreVersionMajorMinorPatchVersion.Minor}"; + + return ( + bundledTemplateMsiVersion, + bundledTemplateInstallPath, + bundledTemplateMajorMinorVersion); + } + + private static (bool isStableVersion, string aspNetCoreVersionMajorMinorPatchVersion) + GetAspNetCoreVersionMajorMinorPatchVersion(string aspNetCorePackageVersionTemplate) + { + var indexOfAspNetCoreVersionPreReleaseSeparator = aspNetCorePackageVersionTemplate.IndexOf('-'); + string aspNetCoreVersionMajorMinorPatchVersion; + if (indexOfAspNetCoreVersionPreReleaseSeparator != -1) + { + aspNetCoreVersionMajorMinorPatchVersion = + aspNetCorePackageVersionTemplate.Substring(0, indexOfAspNetCoreVersionPreReleaseSeparator); + } + else + { + aspNetCoreVersionMajorMinorPatchVersion = aspNetCorePackageVersionTemplate; + } + + return (indexOfAspNetCoreVersionPreReleaseSeparator == -1, aspNetCoreVersionMajorMinorPatchVersion); + } + } +} diff --git a/src/redist/targets/BuildCoreSdkTasks.targets b/src/redist/targets/BuildCoreSdkTasks.targets index 7ffb389a9..d876cb37f 100644 --- a/src/redist/targets/BuildCoreSdkTasks.targets +++ b/src/redist/targets/BuildCoreSdkTasks.targets @@ -19,6 +19,7 @@ Properties="ArtifactsDir=$(ArtifactsDir)tasks\"/> + diff --git a/src/redist/targets/BundledTemplates.targets b/src/redist/targets/BundledTemplates.targets index c24479389..709da201f 100644 --- a/src/redist/targets/BundledTemplates.targets +++ b/src/redist/targets/BundledTemplates.targets @@ -1,47 +1,38 @@ - - $(AspNetCorePackageVersionFor31Templates.IndexOf('-')) - $(AspNetCorePackageVersionFor31Templates) - $(AspNetCorePackageVersionFor31Templates.Substring(0, $(AspNetCore31VersionPreReleaseSeparator))) - $(AspNetCore31VersionMajorMinorPatchVersion).$(GitCommitCount) - $(AspNetCore31VersionMajorMinorPatchVersion) - $(BundledTemplates31InstallPath)-$(VersionSuffix) - $([MSBuild]::Add($(AspNetCore31VersionMajorMinorPatchVersion.IndexOf('.')), 1)) - $(AspNetCore31VersionMajorMinorPatchVersion.IndexOf('.', $(Templates31VersionPatchSeparatorIndex))) - $(AspNetCore31VersionMajorMinorPatchVersion.Substring(0, $(Templates31VersionPatchSeparatorIndex))) - $(AspNetCorePackageVersionFor30Templates.IndexOf('-')) - $(AspNetCorePackageVersionFor30Templates) - $(AspNetCorePackageVersionFor30Templates.Substring(0, $(AspNetCore30VersionPreReleaseSeparator))) - $(AspNetCore30VersionMajorMinorPatchVersion).$(GitCommitCount) - $(AspNetCore30VersionMajorMinorPatchVersion) - $(BundledTemplates30InstallPath)-$(VersionSuffix) - $([MSBuild]::Add($(AspNetCore30VersionMajorMinorPatchVersion.IndexOf('.')), 1)) - $(AspNetCore30VersionMajorMinorPatchVersion.IndexOf('.', $(Templates30VersionPatchSeparatorIndex))) - $(AspNetCore30VersionMajorMinorPatchVersion.Substring(0, $(Templates30VersionPatchSeparatorIndex))) + + + + + - $(AspNetCorePackageVersionFor22Templates.IndexOf('-')) - $(AspNetCorePackageVersionFor22Templates) - $(AspNetCorePackageVersionFor22Templates.Substring(0, $(AspNetCore22VersionPreReleaseSeparator))) - $(AspNetCore22VersionMajorMinorPatchVersion).$(GitCommitCount) - $(AspNetCore22VersionMajorMinorPatchVersion) - $(BundledTemplates22InstallPath)-$(VersionSuffix) - $([MSBuild]::Add($(AspNetCore22VersionMajorMinorPatchVersion.IndexOf('.')), 1)) - $(AspNetCore22VersionMajorMinorPatchVersion.IndexOf('.', $(Templates22VersionPatchSeparatorIndex))) - $(AspNetCore22VersionMajorMinorPatchVersion.Substring(0, $(Templates22VersionPatchSeparatorIndex))) + + + + + - $(AspNetCorePackageVersionFor21Templates.IndexOf('-')) - $(AspNetCorePackageVersionFor21Templates) - $(AspNetCorePackageVersionFor21Templates.Substring(0, $(AspNetCore21VersionPreReleaseSeparator))) - $(AspNetCore21VersionMajorMinorPatchVersion).$(GitCommitCount) - $(AspNetCore21VersionMajorMinorPatchVersion) - $(BundledTemplates21InstallPath)-$(VersionSuffix) - $([MSBuild]::Add($(AspNetCore21VersionMajorMinorPatchVersion.IndexOf('.')), 1)) - $(AspNetCore21VersionMajorMinorPatchVersion.IndexOf('.', $(Templates21VersionPatchSeparatorIndex))) - $(AspNetCore21VersionMajorMinorPatchVersion.Substring(0, $(Templates21VersionPatchSeparatorIndex))) - + + + + + + + + + + + diff --git a/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs b/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs new file mode 100644 index 000000000..6f5ca3919 --- /dev/null +++ b/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs @@ -0,0 +1,27 @@ +using FluentAssertions; +using Xunit; +using Microsoft.DotNet.Cli.Build; + +namespace EndToEnd +{ + public class CalculateTemplateVerionsTests + { + [Fact] + public void ItCanCalculateTemplateVersionsInStableBuilds() + { + var result = CalculateTemplateVersions.Calculate("3.1.0", "014885", "dev"); + result.BundledTemplateInstallPath.Should().Be("3.1.0"); + result.BundledTemplateMsiVersion.Should().Be("3.1.0.014885"); + result.BundledTemplateMajorMinorVersion.Should().Be("3.1"); + } + + [Fact] + public void ItCanCalculateTemplateVersionsInNonStableBuilds() + { + var result = CalculateTemplateVersions.Calculate("5.0.0-alpha.1.20071.6", "014885", "dev"); + result.BundledTemplateInstallPath.Should().Be("5.0.0-dev"); + result.BundledTemplateMsiVersion.Should().Be("5.0.0.014885"); + result.BundledTemplateMajorMinorVersion.Should().Be("5.0"); + } + } +} diff --git a/test/core-sdk-tasks.Tests/core-sdk-tasks.Tests.csproj b/test/core-sdk-tasks.Tests/core-sdk-tasks.Tests.csproj new file mode 100644 index 000000000..47b6ce517 --- /dev/null +++ b/test/core-sdk-tasks.Tests/core-sdk-tasks.Tests.csproj @@ -0,0 +1,14 @@ + + + $(CoreSdkTargetFramework);net472 + $(CoreSdkTargetFramework) + + + + + + + + + + \ No newline at end of file From fdda58e6ffd7040a86fa9e1f04a18acd21c46208 Mon Sep 17 00:00:00 2001 From: William Li Date: Sat, 25 Jan 2020 17:15:10 -0800 Subject: [PATCH 3/5] Use nuget version to better reduce code --- .../CalculateTemplateVersions.cs | 41 +++++-------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/src/core-sdk-tasks/CalculateTemplateVersions.cs b/src/core-sdk-tasks/CalculateTemplateVersions.cs index 7d02618d3..478eeebb4 100644 --- a/src/core-sdk-tasks/CalculateTemplateVersions.cs +++ b/src/core-sdk-tasks/CalculateTemplateVersions.cs @@ -2,8 +2,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using NuGet.Versioning; namespace Microsoft.DotNet.Cli.Build { @@ -43,42 +45,19 @@ namespace Microsoft.DotNet.Cli.Build string BundledTemplateMajorMinorVersion) Calculate(string aspNetCorePackageVersionTemplate, string gitCommitCount, string versionSuffix) { - (bool isStableVersion, string aspNetCoreVersionMajorMinorPatchVersion) = - GetAspNetCoreVersionMajorMinorPatchVersion(aspNetCorePackageVersionTemplate); + var aspNetCoreTemplate = NuGetVersion.Parse(aspNetCorePackageVersionTemplate); - var bundledTemplateMsiVersion = $"{aspNetCoreVersionMajorMinorPatchVersion}.{gitCommitCount}"; + var baseMajorMinorPatch = new NuGetVersion(aspNetCoreTemplate.Major, aspNetCoreTemplate.Minor, + aspNetCoreTemplate.Patch); - string bundledTemplateInstallPath = isStableVersion - ? aspNetCoreVersionMajorMinorPatchVersion - : $"{aspNetCoreVersionMajorMinorPatchVersion}-{versionSuffix}"; - - var parsedAspNetCoreVersionMajorMinorPatchVersion = - System.Version.Parse(aspNetCoreVersionMajorMinorPatchVersion); - var bundledTemplateMajorMinorVersion = - $"{parsedAspNetCoreVersionMajorMinorPatchVersion.Major}.{parsedAspNetCoreVersionMajorMinorPatchVersion.Minor}"; + string bundledTemplateInstallPath = aspNetCoreTemplate.IsPrerelease + ? $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}-{versionSuffix}" + : $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}"; return ( - bundledTemplateMsiVersion, + $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}.{gitCommitCount}", bundledTemplateInstallPath, - bundledTemplateMajorMinorVersion); - } - - private static (bool isStableVersion, string aspNetCoreVersionMajorMinorPatchVersion) - GetAspNetCoreVersionMajorMinorPatchVersion(string aspNetCorePackageVersionTemplate) - { - var indexOfAspNetCoreVersionPreReleaseSeparator = aspNetCorePackageVersionTemplate.IndexOf('-'); - string aspNetCoreVersionMajorMinorPatchVersion; - if (indexOfAspNetCoreVersionPreReleaseSeparator != -1) - { - aspNetCoreVersionMajorMinorPatchVersion = - aspNetCorePackageVersionTemplate.Substring(0, indexOfAspNetCoreVersionPreReleaseSeparator); - } - else - { - aspNetCoreVersionMajorMinorPatchVersion = aspNetCorePackageVersionTemplate; - } - - return (indexOfAspNetCoreVersionPreReleaseSeparator == -1, aspNetCoreVersionMajorMinorPatchVersion); + $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}"); } } } From df09f073942ecac1aa39f89c0bf66c35a31e60aa Mon Sep 17 00:00:00 2001 From: William Li Date: Sat, 25 Jan 2020 17:32:35 -0800 Subject: [PATCH 4/5] Finish ComponentID reset --- src/core-sdk-tasks/CalculateTemplateVersions.cs | 7 ++++++- .../CalculateTemplateVerionsTests.cs | 11 ++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core-sdk-tasks/CalculateTemplateVersions.cs b/src/core-sdk-tasks/CalculateTemplateVersions.cs index 478eeebb4..abbc987fe 100644 --- a/src/core-sdk-tasks/CalculateTemplateVersions.cs +++ b/src/core-sdk-tasks/CalculateTemplateVersions.cs @@ -29,6 +29,8 @@ namespace Microsoft.DotNet.Cli.Build [Output] public string BundledTemplateMajorMinorVersion { get; set; } + private const int _patchVersionResetOffset = 1; + public override bool Execute() { var result = Calculate(AspNetCorePackageVersionTemplate, GitCommitCount, VersionSuffix); @@ -47,8 +49,11 @@ namespace Microsoft.DotNet.Cli.Build { var aspNetCoreTemplate = NuGetVersion.Parse(aspNetCorePackageVersionTemplate); + // due to historical bug https://github.com/dotnet/core-sdk/issues/6243 + // we need to increase patch version by one in order to "reset" existing install ComponentId + // more in the above bug's detail var baseMajorMinorPatch = new NuGetVersion(aspNetCoreTemplate.Major, aspNetCoreTemplate.Minor, - aspNetCoreTemplate.Patch); + aspNetCoreTemplate.Patch + _patchVersionResetOffset); string bundledTemplateInstallPath = aspNetCoreTemplate.IsPrerelease ? $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}-{versionSuffix}" diff --git a/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs b/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs index 6f5ca3919..041337b45 100644 --- a/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs +++ b/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs @@ -4,14 +4,15 @@ using Microsoft.DotNet.Cli.Build; namespace EndToEnd { - public class CalculateTemplateVerionsTests + public class CalculateTemplateVersionsTests { [Fact] public void ItCanCalculateTemplateVersionsInStableBuilds() { var result = CalculateTemplateVersions.Calculate("3.1.0", "014885", "dev"); - result.BundledTemplateInstallPath.Should().Be("3.1.0"); - result.BundledTemplateMsiVersion.Should().Be("3.1.0.014885"); + result.BundledTemplateInstallPath.Should().Be("3.1.1", + "the patch is 1 higher than aspnetTemplateVersion due to https://github.com/dotnet/core-sdk/issues/6243"); + result.BundledTemplateMsiVersion.Should().Be("3.1.1.014885"); result.BundledTemplateMajorMinorVersion.Should().Be("3.1"); } @@ -19,8 +20,8 @@ namespace EndToEnd public void ItCanCalculateTemplateVersionsInNonStableBuilds() { var result = CalculateTemplateVersions.Calculate("5.0.0-alpha.1.20071.6", "014885", "dev"); - result.BundledTemplateInstallPath.Should().Be("5.0.0-dev"); - result.BundledTemplateMsiVersion.Should().Be("5.0.0.014885"); + result.BundledTemplateInstallPath.Should().Be("5.0.1-dev"); + result.BundledTemplateMsiVersion.Should().Be("5.0.1.014885"); result.BundledTemplateMajorMinorVersion.Should().Be("5.0"); } } From 3e8b475e2f91bea9550f1fc199c326e1669e4328 Mon Sep 17 00:00:00 2001 From: William Li Date: Tue, 28 Jan 2020 10:49:14 -0800 Subject: [PATCH 5/5] Cap major 5 --- .../CalculateTemplateVersions.cs | 26 +++++++++---- .../CalculateTemplateVerionsTests.cs | 39 ++++++++++++++----- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/core-sdk-tasks/CalculateTemplateVersions.cs b/src/core-sdk-tasks/CalculateTemplateVersions.cs index abbc987fe..55d58fd40 100644 --- a/src/core-sdk-tasks/CalculateTemplateVersions.cs +++ b/src/core-sdk-tasks/CalculateTemplateVersions.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using NuGet.Versioning; @@ -49,11 +47,7 @@ namespace Microsoft.DotNet.Cli.Build { var aspNetCoreTemplate = NuGetVersion.Parse(aspNetCorePackageVersionTemplate); - // due to historical bug https://github.com/dotnet/core-sdk/issues/6243 - // we need to increase patch version by one in order to "reset" existing install ComponentId - // more in the above bug's detail - var baseMajorMinorPatch = new NuGetVersion(aspNetCoreTemplate.Major, aspNetCoreTemplate.Minor, - aspNetCoreTemplate.Patch + _patchVersionResetOffset); + NuGetVersion baseMajorMinorPatch = GetBaseMajorMinorPatch(aspNetCoreTemplate); string bundledTemplateInstallPath = aspNetCoreTemplate.IsPrerelease ? $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}-{versionSuffix}" @@ -64,5 +58,23 @@ namespace Microsoft.DotNet.Cli.Build bundledTemplateInstallPath, $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}"); } + + private static NuGetVersion GetBaseMajorMinorPatch(NuGetVersion aspNetCoreTemplate) + { + // due to historical bug https://github.com/dotnet/core-sdk/issues/6243 + // we need to increase patch version by one in order to "reset" existing install ComponentId + // more in the above bug's detail. + // There is no non-deterministic existing ComponentId under Major version 5. + // so only apply the patch bump when below 5 + + int basePatch = + aspNetCoreTemplate.Major < 5 + ? aspNetCoreTemplate.Patch + _patchVersionResetOffset + : aspNetCoreTemplate.Patch; + + var baseMajorMinorPatch = new NuGetVersion(aspNetCoreTemplate.Major, aspNetCoreTemplate.Minor, + basePatch); + return baseMajorMinorPatch; + } } } diff --git a/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs b/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs index 041337b45..8f25cc34e 100644 --- a/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs +++ b/test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs @@ -7,22 +7,43 @@ namespace EndToEnd public class CalculateTemplateVersionsTests { [Fact] - public void ItCanCalculateTemplateVersionsInStableBuilds() + public void WhenAspNetCoreTemplateMajorVersionLowerthan3ItCanCalculateTemplateVersionsInStableBuilds() { var result = CalculateTemplateVersions.Calculate("3.1.0", "014885", "dev"); - result.BundledTemplateInstallPath.Should().Be("3.1.1", - "the patch is 1 higher than aspnetTemplateVersion due to https://github.com/dotnet/core-sdk/issues/6243"); - result.BundledTemplateMsiVersion.Should().Be("3.1.1.014885"); - result.BundledTemplateMajorMinorVersion.Should().Be("3.1"); + + result.Should() + .Be(("3.1.1.014885", "3.1.1", "3.1"), + "the patch is 1 higher than aspnetTemplateVersion " + + "due to https://github.com/dotnet/core-sdk/issues/6243"); } [Fact] - public void ItCanCalculateTemplateVersionsInNonStableBuilds() + public void WhenAspNetCoreTemplateMajorVersionLowerthan3ItCanCalculateTemplateVersionsInNonStableBuilds() + { + var result = CalculateTemplateVersions.Calculate("3.0.0-alpha.1.20071.6", "014885", "dev"); + + result.Should() + .Be(("3.0.1.014885", "3.0.1-dev", "3.0")); + } + + [Fact] + public void WhenAspNetCoreTemplateMajorVersionHigherthan3ItCanCalculateTemplateVersionsInStableBuilds() + { + var result = CalculateTemplateVersions.Calculate("5.1.0", "014885", "dev"); + + result.Should() + .Be(("5.1.0.014885", "5.1.0", "5.1"), + "the patch align with AspNetCoreTemplateMajorVersion again, " + + "since there is no non-deterministic existing ComponentId under Major version 5."); + } + + [Fact] + public void WhenAspNetCoreTemplateMajorVersionHigherthan3ItCanCalculateTemplateVersionsInNonStableBuilds() { var result = CalculateTemplateVersions.Calculate("5.0.0-alpha.1.20071.6", "014885", "dev"); - result.BundledTemplateInstallPath.Should().Be("5.0.1-dev"); - result.BundledTemplateMsiVersion.Should().Be("5.0.1.014885"); - result.BundledTemplateMajorMinorVersion.Should().Be("5.0"); + + result.Should() + .Be(("5.0.0.014885", "5.0.0-dev", "5.0")); } } }