Skip to content

Commit 0806ef1

Browse files
author
William Li
committed
Use Task to calculate template versions
No behaivor change
1 parent 252416a commit 0806ef1

6 files changed

+165
-41
lines changed

Microsoft.DotNet.Cli.sln

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Dotnet.Sdk.Intern
2121
EndProject
2222
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SdkTests", "test\SdkTests\SdkTests.csproj", "{CB1EE94E-CB83-4071-9DD0-9929AE2B7282}"
2323
EndProject
24+
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}"
25+
EndProject
2426
Global
2527
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2628
Debug|Any CPU = Debug|Any CPU
@@ -55,6 +57,10 @@ Global
5557
{CB1EE94E-CB83-4071-9DD0-9929AE2B7282}.Debug|Any CPU.Build.0 = Debug|Any CPU
5658
{CB1EE94E-CB83-4071-9DD0-9929AE2B7282}.Release|Any CPU.ActiveCfg = Release|Any CPU
5759
{CB1EE94E-CB83-4071-9DD0-9929AE2B7282}.Release|Any CPU.Build.0 = Release|Any CPU
60+
{658EF9BE-452C-4D31-AA24-B9E2235799A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61+
{658EF9BE-452C-4D31-AA24-B9E2235799A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
62+
{658EF9BE-452C-4D31-AA24-B9E2235799A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
63+
{658EF9BE-452C-4D31-AA24-B9E2235799A8}.Release|Any CPU.Build.0 = Release|Any CPU
5864
EndGlobalSection
5965
GlobalSection(SolutionProperties) = preSolution
6066
HideSolutionNode = FALSE
@@ -66,6 +72,7 @@ Global
6672
{78E15EC1-7732-41E3-8591-934E9F583254} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
6773
{7EE15292-2CAD-44FA-8A1F-BAC4688A49E0} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
6874
{CB1EE94E-CB83-4071-9DD0-9929AE2B7282} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
75+
{658EF9BE-452C-4D31-AA24-B9E2235799A8} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
6976
EndGlobalSection
7077
GlobalSection(ExtensibilityGlobals) = postSolution
7178
SolutionGuid = {B526D2CE-EE2D-4AD4-93EF-1867D90FF1F5}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using Microsoft.Build.Framework;
6+
using Microsoft.Build.Utilities;
7+
8+
namespace Microsoft.DotNet.Cli.Build
9+
{
10+
public class CalculateTemplateVersions : Task
11+
{
12+
[Required]
13+
public string AspNetCorePackageVersionTemplate { get; set; }
14+
15+
[Required]
16+
public string GitCommitCount { get; set; }
17+
18+
[Required]
19+
public string VersionSuffix { get; set; }
20+
21+
[Output]
22+
public string BundledTemplateMSIVersion { get; set; }
23+
24+
[Output]
25+
public string BundledTemplateInstallPath { get; set; }
26+
27+
[Output]
28+
public string BundledTemplateMajorMinorVersion { get; set; }
29+
30+
public override bool Execute()
31+
{
32+
var result = Calculate(AspNetCorePackageVersionTemplate, GitCommitCount, VersionSuffix);
33+
BundledTemplateMSIVersion = result.BundledTemplateMsiVersion;
34+
BundledTemplateInstallPath = result.BundledTemplateInstallPath;
35+
BundledTemplateMajorMinorVersion = result.BundledTemplateMajorMinorVersion;
36+
37+
return true;
38+
}
39+
40+
public static
41+
(string BundledTemplateMsiVersion,
42+
string BundledTemplateInstallPath,
43+
string BundledTemplateMajorMinorVersion) Calculate(string aspNetCorePackageVersionTemplate,
44+
string gitCommitCount, string versionSuffix)
45+
{
46+
(bool isStableVersion, string aspNetCoreVersionMajorMinorPatchVersion) =
47+
GetAspNetCoreVersionMajorMinorPatchVersion(aspNetCorePackageVersionTemplate);
48+
49+
var bundledTemplateMsiVersion = $"{aspNetCoreVersionMajorMinorPatchVersion}.{gitCommitCount}";
50+
51+
string bundledTemplateInstallPath = isStableVersion
52+
? aspNetCoreVersionMajorMinorPatchVersion
53+
: $"{aspNetCoreVersionMajorMinorPatchVersion}-{versionSuffix}";
54+
55+
var parsedAspNetCoreVersionMajorMinorPatchVersion =
56+
System.Version.Parse(aspNetCoreVersionMajorMinorPatchVersion);
57+
var bundledTemplateMajorMinorVersion =
58+
$"{parsedAspNetCoreVersionMajorMinorPatchVersion.Major}.{parsedAspNetCoreVersionMajorMinorPatchVersion.Minor}";
59+
60+
return (
61+
bundledTemplateMsiVersion,
62+
bundledTemplateInstallPath,
63+
bundledTemplateMajorMinorVersion);
64+
}
65+
66+
private static (bool isStableVersion, string aspNetCoreVersionMajorMinorPatchVersion)
67+
GetAspNetCoreVersionMajorMinorPatchVersion(string aspNetCorePackageVersionTemplate)
68+
{
69+
var indexOfAspNetCoreVersionPreReleaseSeparator = aspNetCorePackageVersionTemplate.IndexOf('-');
70+
string aspNetCoreVersionMajorMinorPatchVersion;
71+
if (indexOfAspNetCoreVersionPreReleaseSeparator != -1)
72+
{
73+
aspNetCoreVersionMajorMinorPatchVersion =
74+
aspNetCorePackageVersionTemplate.Substring(0, indexOfAspNetCoreVersionPreReleaseSeparator);
75+
}
76+
else
77+
{
78+
aspNetCoreVersionMajorMinorPatchVersion = aspNetCorePackageVersionTemplate;
79+
}
80+
81+
return (indexOfAspNetCoreVersionPreReleaseSeparator == -1, aspNetCoreVersionMajorMinorPatchVersion);
82+
}
83+
}
84+
}

src/redist/targets/BuildCoreSdkTasks.targets

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Properties="ArtifactsDir=$(ArtifactsDir)tasks\"/>
2020
</Target>
2121

22+
<UsingTask TaskName="CalculateTemplateVersions" AssemblyFile="$(CoreSdkTaskDll)" />
2223
<UsingTask TaskName="GetCurrentRuntimeInformation" AssemblyFile="$(CoreSdkTaskDll)" />
2324
<UsingTask TaskName="DownloadFile" AssemblyFile="$(CoreSdkTaskDll)" />
2425
<UsingTask TaskName="ExtractArchiveToDirectory" AssemblyFile="$(CoreSdkTaskDll)" />

src/redist/targets/BundledTemplates.targets

+32-41
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,38 @@
11
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<Target Name="CalculateTemplatesVersions"
33
DependsOnTargets="SetSdkVersionInfo">
4-
<PropertyGroup>
5-
<AspNetCore31VersionPreReleaseSeparator>$(AspNetCorePackageVersionFor31Templates.IndexOf('-'))</AspNetCore31VersionPreReleaseSeparator>
6-
<AspNetCore31VersionMajorMinorPatchVersion>$(AspNetCorePackageVersionFor31Templates)</AspNetCore31VersionMajorMinorPatchVersion>
7-
<AspNetCore31VersionMajorMinorPatchVersion Condition=" '$(AspNetCore31VersionPreReleaseSeparator)' != -1 ">$(AspNetCorePackageVersionFor31Templates.Substring(0, $(AspNetCore31VersionPreReleaseSeparator)))</AspNetCore31VersionMajorMinorPatchVersion>
8-
<BundledTemplates31MSIVersion>$(AspNetCore31VersionMajorMinorPatchVersion).$(GitCommitCount)</BundledTemplates31MSIVersion>
9-
<BundledTemplates31InstallPath>$(AspNetCore31VersionMajorMinorPatchVersion)</BundledTemplates31InstallPath>
10-
<BundledTemplates31InstallPath Condition=" '$(AspNetCore31VersionPreReleaseSeparator)' != -1 ">$(BundledTemplates31InstallPath)-$(VersionSuffix)</BundledTemplates31InstallPath>
11-
<Templates31VersionPatchSeparatorIndex>$([MSBuild]::Add($(AspNetCore31VersionMajorMinorPatchVersion.IndexOf('.')), 1))</Templates31VersionPatchSeparatorIndex>
12-
<Templates31VersionPatchSeparatorIndex>$(AspNetCore31VersionMajorMinorPatchVersion.IndexOf('.', $(Templates31VersionPatchSeparatorIndex)))</Templates31VersionPatchSeparatorIndex>
13-
<BundledTemplates31MajorMinorVersion>$(AspNetCore31VersionMajorMinorPatchVersion.Substring(0, $(Templates31VersionPatchSeparatorIndex)))</BundledTemplates31MajorMinorVersion>
14-
15-
<AspNetCore30VersionPreReleaseSeparator>$(AspNetCorePackageVersionFor30Templates.IndexOf('-'))</AspNetCore30VersionPreReleaseSeparator>
16-
<AspNetCore30VersionMajorMinorPatchVersion>$(AspNetCorePackageVersionFor30Templates)</AspNetCore30VersionMajorMinorPatchVersion>
17-
<AspNetCore30VersionMajorMinorPatchVersion Condition=" '$(AspNetCore30VersionPreReleaseSeparator)' != -1 ">$(AspNetCorePackageVersionFor30Templates.Substring(0, $(AspNetCore30VersionPreReleaseSeparator)))</AspNetCore30VersionMajorMinorPatchVersion>
18-
<BundledTemplates30MSIVersion>$(AspNetCore30VersionMajorMinorPatchVersion).$(GitCommitCount)</BundledTemplates30MSIVersion>
19-
<BundledTemplates30InstallPath>$(AspNetCore30VersionMajorMinorPatchVersion)</BundledTemplates30InstallPath>
20-
<BundledTemplates30InstallPath Condition=" '$(AspNetCore30VersionPreReleaseSeparator)' != -1 ">$(BundledTemplates30InstallPath)-$(VersionSuffix)</BundledTemplates30InstallPath>
21-
<Templates30VersionPatchSeparatorIndex>$([MSBuild]::Add($(AspNetCore30VersionMajorMinorPatchVersion.IndexOf('.')), 1))</Templates30VersionPatchSeparatorIndex>
22-
<Templates30VersionPatchSeparatorIndex>$(AspNetCore30VersionMajorMinorPatchVersion.IndexOf('.', $(Templates30VersionPatchSeparatorIndex)))</Templates30VersionPatchSeparatorIndex>
23-
<BundledTemplates30MajorMinorVersion>$(AspNetCore30VersionMajorMinorPatchVersion.Substring(0, $(Templates30VersionPatchSeparatorIndex)))</BundledTemplates30MajorMinorVersion>
24-
25-
<AspNetCore22VersionPreReleaseSeparator>$(AspNetCorePackageVersionFor22Templates.IndexOf('-'))</AspNetCore22VersionPreReleaseSeparator>
26-
<AspNetCore22VersionMajorMinorPatchVersion>$(AspNetCorePackageVersionFor22Templates)</AspNetCore22VersionMajorMinorPatchVersion>
27-
<AspNetCore22VersionMajorMinorPatchVersion Condition=" '$(AspNetCore22VersionPreReleaseSeparator)' != -1 ">$(AspNetCorePackageVersionFor22Templates.Substring(0, $(AspNetCore22VersionPreReleaseSeparator)))</AspNetCore22VersionMajorMinorPatchVersion>
28-
<BundledTemplates22MSIVersion>$(AspNetCore22VersionMajorMinorPatchVersion).$(GitCommitCount)</BundledTemplates22MSIVersion>
29-
<BundledTemplates22InstallPath>$(AspNetCore22VersionMajorMinorPatchVersion)</BundledTemplates22InstallPath>
30-
<BundledTemplates22InstallPath Condition=" '$(AspNetCore22VersionPreReleaseSeparator)' != -1 ">$(BundledTemplates22InstallPath)-$(VersionSuffix)</BundledTemplates22InstallPath>
31-
<Templates22VersionPatchSeparatorIndex>$([MSBuild]::Add($(AspNetCore22VersionMajorMinorPatchVersion.IndexOf('.')), 1))</Templates22VersionPatchSeparatorIndex>
32-
<Templates22VersionPatchSeparatorIndex>$(AspNetCore22VersionMajorMinorPatchVersion.IndexOf('.', $(Templates22VersionPatchSeparatorIndex)))</Templates22VersionPatchSeparatorIndex>
33-
<BundledTemplates22MajorMinorVersion>$(AspNetCore22VersionMajorMinorPatchVersion.Substring(0, $(Templates22VersionPatchSeparatorIndex)))</BundledTemplates22MajorMinorVersion>
34-
35-
<AspNetCore21VersionPreReleaseSeparator>$(AspNetCorePackageVersionFor21Templates.IndexOf('-'))</AspNetCore21VersionPreReleaseSeparator>
36-
<AspNetCore21VersionMajorMinorPatchVersion>$(AspNetCorePackageVersionFor21Templates)</AspNetCore21VersionMajorMinorPatchVersion>
37-
<AspNetCore21VersionMajorMinorPatchVersion Condition=" '$(AspNetCore21VersionPreReleaseSeparator)' != -1 ">$(AspNetCorePackageVersionFor21Templates.Substring(0, $(AspNetCore21VersionPreReleaseSeparator)))</AspNetCore21VersionMajorMinorPatchVersion>
38-
<BundledTemplates21MSIVersion>$(AspNetCore21VersionMajorMinorPatchVersion).$(GitCommitCount)</BundledTemplates21MSIVersion>
39-
<BundledTemplates21InstallPath>$(AspNetCore21VersionMajorMinorPatchVersion)</BundledTemplates21InstallPath>
40-
<BundledTemplates21InstallPath Condition=" '$(AspNetCore21VersionPreReleaseSeparator)' != -1 ">$(BundledTemplates21InstallPath)-$(VersionSuffix)</BundledTemplates21InstallPath>
41-
<Templates21VersionPatchSeparatorIndex>$([MSBuild]::Add($(AspNetCore21VersionMajorMinorPatchVersion.IndexOf('.')), 1))</Templates21VersionPatchSeparatorIndex>
42-
<Templates21VersionPatchSeparatorIndex>$(AspNetCore21VersionMajorMinorPatchVersion.IndexOf('.', $(Templates21VersionPatchSeparatorIndex)))</Templates21VersionPatchSeparatorIndex>
43-
<BundledTemplates21MajorMinorVersion>$(AspNetCore21VersionMajorMinorPatchVersion.Substring(0, $(Templates21VersionPatchSeparatorIndex)))</BundledTemplates21MajorMinorVersion>
44-
</PropertyGroup>
4+
5+
<CalculateTemplateVersions AspNetCorePackageVersionTemplate="$(AspNetCorePackageVersionFor31Templates)"
6+
GitCommitCount="$(GitCommitCount)"
7+
VersionSuffix="$(VersionSuffix)">
8+
<Output TaskParameter="BundledTemplateMSIVersion" PropertyName="BundledTemplates31MSIVersion" />
9+
<Output TaskParameter="BundledTemplateInstallPath" PropertyName="BundledTemplates31InstallPath" />
10+
<Output TaskParameter="BundledTemplateMajorMinorVersion" PropertyName="BundledTemplates31MajorMinorVersion" />
11+
</CalculateTemplateVersions>
12+
13+
<CalculateTemplateVersions AspNetCorePackageVersionTemplate="$(AspNetCorePackageVersionFor30Templates)"
14+
GitCommitCount="$(GitCommitCount)"
15+
VersionSuffix="$(VersionSuffix)">
16+
<Output TaskParameter="BundledTemplateMSIVersion" PropertyName="BundledTemplates30MSIVersion" />
17+
<Output TaskParameter="BundledTemplateInstallPath" PropertyName="BundledTemplates30InstallPath" />
18+
<Output TaskParameter="BundledTemplateMajorMinorVersion" PropertyName="BundledTemplates30MajorMinorVersion" />
19+
</CalculateTemplateVersions>
20+
21+
<CalculateTemplateVersions AspNetCorePackageVersionTemplate="$(AspNetCorePackageVersionFor22Templates)"
22+
GitCommitCount="$(GitCommitCount)"
23+
VersionSuffix="$(VersionSuffix)">
24+
<Output TaskParameter="BundledTemplateMSIVersion" PropertyName="BundledTemplates22MSIVersion" />
25+
<Output TaskParameter="BundledTemplateInstallPath" PropertyName="BundledTemplates22InstallPath" />
26+
<Output TaskParameter="BundledTemplateMajorMinorVersion" PropertyName="BundledTemplates22MajorMinorVersion" />
27+
</CalculateTemplateVersions>
28+
29+
<CalculateTemplateVersions AspNetCorePackageVersionTemplate="$(AspNetCorePackageVersionFor21Templates)"
30+
GitCommitCount="$(GitCommitCount)"
31+
VersionSuffix="$(VersionSuffix)">
32+
<Output TaskParameter="BundledTemplateMSIVersion" PropertyName="BundledTemplates21MSIVersion" />
33+
<Output TaskParameter="BundledTemplateInstallPath" PropertyName="BundledTemplates21InstallPath" />
34+
<Output TaskParameter="BundledTemplateMajorMinorVersion" PropertyName="BundledTemplates21MajorMinorVersion" />
35+
</CalculateTemplateVersions>
4536
</Target>
4637

4738
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
using Microsoft.DotNet.Cli.Build;
4+
5+
namespace EndToEnd
6+
{
7+
public class CalculateTemplateVerionsTests
8+
{
9+
[Fact]
10+
public void ItCanCalculateTemplateVersionsInStableBuilds()
11+
{
12+
var result = CalculateTemplateVersions.Calculate("3.1.0", "014885", "dev");
13+
result.BundledTemplateInstallPath.Should().Be("3.1.0");
14+
result.BundledTemplateMsiVersion.Should().Be("3.1.0.014885");
15+
result.BundledTemplateMajorMinorVersion.Should().Be("3.1");
16+
}
17+
18+
[Fact]
19+
public void ItCanCalculateTemplateVersionsInNonStableBuilds()
20+
{
21+
var result = CalculateTemplateVersions.Calculate("5.0.0-alpha.1.20071.6", "014885", "dev");
22+
result.BundledTemplateInstallPath.Should().Be("5.0.0-dev");
23+
result.BundledTemplateMsiVersion.Should().Be("5.0.0.014885");
24+
result.BundledTemplateMajorMinorVersion.Should().Be("5.0");
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<TargetFrameworks>$(CoreSdkTargetFramework);net472</TargetFrameworks>
4+
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">$(CoreSdkTargetFramework)</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="FluentAssertions" Version="4.18.0" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\..\src\core-sdk-tasks\core-sdk-tasks.csproj" />
13+
</ItemGroup>
14+
</Project>

0 commit comments

Comments
 (0)