
This change is required for RTM stable builds. When stable versions are generated the CalculateTemplateVersions task will fail. For .NET 3.x, installer is partially on arcade. It uses its own versioning model, but the arcade generated versions are actually set (specifically VersionSuffix). So even when stable builds are generated, VersionSuffix is available. It is unused when the aspnetcore template versions are stable. For .NET 5, installer is now fully on arcade versioning, which means VersionSuffix is not set when stable versions are generated. Instead of using installer's version suffix if aspnetcore's template versions are unstable, use the version suffix of the aspnetcore template versions. This subtley affects the installer directory of the templates: If the aspnetcore version is: 5.0.0-rc.1.1234.5 And the installer version is: 5.0.100-rc.1.9999.9 Then: Template install dir before this change: .dotnet\templates\5.0.0-rc.1.9999.9 Template install dir after this change: .dotnet\templates\5.0.0-rc.1.1234.5 Of note: The overall template layout doesn't make a ton of sense. The aspnetcore template version is used for the install directory, but many different templates are put in this directory, including some that have completely different versions.
74 lines
3 KiB
C#
74 lines
3 KiB
C#
// 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 Microsoft.Build.Framework;
|
|
using Microsoft.Build.Utilities;
|
|
using NuGet.Versioning;
|
|
|
|
namespace Microsoft.DotNet.Cli.Build
|
|
{
|
|
public class CalculateTemplateVersions : Task
|
|
{
|
|
[Required]
|
|
public string AspNetCorePackageVersionTemplate { get; set; }
|
|
|
|
[Output]
|
|
public string BundledTemplateInstallPath { get; set; }
|
|
|
|
[Output]
|
|
public string BundledTemplateMajorMinorVersion { get; set; }
|
|
|
|
[Output]
|
|
public string BundledTemplateMajorMinorPatchVersion { get; set; }
|
|
|
|
private const int _patchVersionResetOffset = 1;
|
|
|
|
public override bool Execute()
|
|
{
|
|
var result = Calculate(AspNetCorePackageVersionTemplate);
|
|
BundledTemplateInstallPath = result.BundledTemplateInstallPath;
|
|
BundledTemplateMajorMinorVersion = result.BundledTemplateMajorMinorVersion;
|
|
BundledTemplateMajorMinorPatchVersion = result.BundledTemplateMajorMinorPatchVersion;
|
|
|
|
return true;
|
|
}
|
|
|
|
public static
|
|
(string BundledTemplateInstallPath,
|
|
string BundledTemplateMajorMinorVersion,
|
|
string BundledTemplateMajorMinorPatchVersion)
|
|
Calculate(string aspNetCorePackageVersionTemplate)
|
|
{
|
|
var aspNetCoreTemplate = NuGetVersion.Parse(aspNetCorePackageVersionTemplate);
|
|
|
|
NuGetVersion baseMajorMinorPatch = GetBaseMajorMinorPatch(aspNetCoreTemplate);
|
|
|
|
string bundledTemplateInstallPath = aspNetCoreTemplate.IsPrerelease
|
|
? $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}-{aspNetCoreTemplate.Release}"
|
|
: $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}";
|
|
|
|
return (
|
|
bundledTemplateInstallPath,
|
|
$"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}",
|
|
$"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}");
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|