Adding automatic generation of DefaultRuntimeFrameworkVersions

This commit is contained in:
Sarah Oslund 2020-03-26 10:01:21 -07:00
parent 2af782ff7d
commit 8cc89ea7e5
4 changed files with 87 additions and 6 deletions

View file

@ -0,0 +1,39 @@
// 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 GenerateDefaultRuntimeFrameworkVersion : Task
{
[Required]
public string RuntimePackVersion { get; set; }
[Output]
public string DefaultRuntimeFrameworkVersion { get; set; }
public override bool Execute()
{
if (NuGetVersion.TryParse(RuntimePackVersion, out var version))
{
if (version.IsPrerelease && version.Patch == 0)
{
DefaultRuntimeFrameworkVersion = RuntimePackVersion;
}
else
{
DefaultRuntimeFrameworkVersion = new NuGetVersion(version.Major, version.Minor, 0).ToFullString();
}
return true;
}
else
{
return false;
}
}
}
}

View file

@ -34,6 +34,7 @@
<UsingTask TaskName="DotNetDebTool" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="BuildFPMToolPreReqs" AssemblyFile="$(CoreSdkTaskDll)"/>
<UsingTask TaskName="GetUseBundledNETCoreAppPackageVersionAsDefaultNetCorePatchVersion" AssemblyFile="$(CoreSdkTaskDll)"/>
<UsingTask TaskName="GenerateDefaultRuntimeFrameworkVersion" AssemblyFile="$(CoreSdkTaskDll)"/>
<UsingTask TaskName="AddMetadataIsPE" AssemblyFile="$(CoreSdkTaskDll)"/>
<UsingTask TaskName="Crossgen" AssemblyFile="$(CoreSdkTaskDll)"/>
<UsingTask TaskName="CopyBlobsToLatest" AssemblyFile="$(CoreSdkTaskDll)"/>

View file

@ -7,8 +7,8 @@
<PropertyGroup>
<BundledVersionsPropsFileName>Microsoft.NETCoreSdk.BundledVersions.props</BundledVersionsPropsFileName>
</PropertyGroup>
<PropertyGroup>
<_NETCoreAppPackageVersion>$(MicrosoftNETCoreAppRuntimePackageVersion)</_NETCoreAppPackageVersion>
<_NETStandardLibraryPackageVersion>$(NETStandardLibraryRefPackageVersion)</_NETStandardLibraryPackageVersion>
@ -92,6 +92,19 @@
PropertyName="_UseBundledNETCoreAppPackageVersionAsDefaultNetCorePatchVersion" />
</GetUseBundledNETCoreAppPackageVersionAsDefaultNetCorePatchVersion>
<!--
Generate default runtime framework versions
-->
<GenerateDefaultRuntimeFrameworkVersion RuntimePackVersion="$(MicrosoftNETCoreAppRuntimePackageVersion)">
<Output TaskParameter="DefaultRuntimeFrameworkVersion" PropertyName="MicrosoftNETCoreAppDefaultRuntimePackageVersion" />
</GenerateDefaultRuntimeFrameworkVersion>
<GenerateDefaultRuntimeFrameworkVersion RuntimePackVersion="$(MicrosoftWindowsDesktopAppRuntimePackageVersion)">
<Output TaskParameter="DefaultRuntimeFrameworkVersion" PropertyName="MicrosoftWindowsDesktopAppDefaultRuntimePackageVersion" />
</GenerateDefaultRuntimeFrameworkVersion>
<GenerateDefaultRuntimeFrameworkVersion RuntimePackVersion="$(MicrosoftAspNetCoreAppRuntimePackageVersion)">
<Output TaskParameter="DefaultRuntimeFrameworkVersion" PropertyName="MicrosoftAspNetCoreAppDefaultRuntimePackageVersion" />
</GenerateDefaultRuntimeFrameworkVersion>
<ItemGroup>
<ImplicitPackageVariable Include="Microsoft.NETCore.App"
TargetFrameworkVersion="1.0"
@ -170,7 +183,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<KnownFrameworkReference Include="Microsoft.NETCore.App"
TargetFramework="netcoreapp5.0"
RuntimeFrameworkName="Microsoft.NETCore.App"
DefaultRuntimeFrameworkVersion="$(MicrosoftNETCoreAppRuntimePackageVersion)"
DefaultRuntimeFrameworkVersion="$(MicrosoftNETCoreAppDefaultRuntimePackageVersion)"
LatestRuntimeFrameworkVersion="$(MicrosoftNETCoreAppRuntimePackageVersion)"
TargetingPackName="Microsoft.NETCore.App.Ref"
TargetingPackVersion="$(MicrosoftNETCoreAppRefPackageVersion)"
@ -196,7 +209,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<KnownFrameworkReference Include="Microsoft.WindowsDesktop.App"
TargetFramework="netcoreapp5.0"
RuntimeFrameworkName="Microsoft.WindowsDesktop.App"
DefaultRuntimeFrameworkVersion="$(MicrosoftWindowsDesktopAppRuntimePackageVersion)"
DefaultRuntimeFrameworkVersion="$(MicrosoftWindowsDesktopAppDefaultRuntimePackageVersion)"
LatestRuntimeFrameworkVersion="$(MicrosoftWindowsDesktopAppRuntimePackageVersion)"
TargetingPackName="Microsoft.WindowsDesktop.App.Ref"
TargetingPackVersion="$(MicrosoftWindowsDesktopAppRefPackageVersion)"
@ -208,7 +221,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<KnownFrameworkReference Include="Microsoft.WindowsDesktop.App.WPF"
TargetFramework="netcoreapp5.0"
RuntimeFrameworkName="Microsoft.WindowsDesktop.App"
DefaultRuntimeFrameworkVersion="$(MicrosoftWindowsDesktopAppRuntimePackageVersion)"
DefaultRuntimeFrameworkVersion="$(MicrosoftWindowsDesktopAppDefaultRuntimePackageVersion)"
LatestRuntimeFrameworkVersion="$(MicrosoftWindowsDesktopAppRuntimePackageVersion)"
TargetingPackName="Microsoft.WindowsDesktop.App.Ref"
TargetingPackVersion="$(MicrosoftWindowsDesktopAppRefPackageVersion)"
@ -221,7 +234,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<KnownFrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms"
TargetFramework="netcoreapp5.0"
RuntimeFrameworkName="Microsoft.WindowsDesktop.App"
DefaultRuntimeFrameworkVersion="$(MicrosoftWindowsDesktopAppRuntimePackageVersion)"
DefaultRuntimeFrameworkVersion="$(MicrosoftWindowsDesktopAppDefaultRuntimePackageVersion)"
LatestRuntimeFrameworkVersion="$(MicrosoftWindowsDesktopAppRuntimePackageVersion)"
TargetingPackName="Microsoft.WindowsDesktop.App.Ref"
TargetingPackVersion="$(MicrosoftWindowsDesktopAppRefPackageVersion)"
@ -234,7 +247,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<KnownFrameworkReference Include="Microsoft.AspNetCore.App"
TargetFramework="netcoreapp5.0"
RuntimeFrameworkName="Microsoft.AspNetCore.App"
DefaultRuntimeFrameworkVersion="$(MicrosoftAspNetCoreAppRuntimePackageVersion)"
DefaultRuntimeFrameworkVersion="$(MicrosoftAspNetCoreAppDefaultRuntimePackageVersion)"
LatestRuntimeFrameworkVersion="$(MicrosoftAspNetCoreAppRuntimePackageVersion)"
TargetingPackName="Microsoft.AspNetCore.App.Ref"
TargetingPackVersion="$(MicrosoftAspNetCoreAppRefPackageVersion)"

View file

@ -0,0 +1,28 @@
using FluentAssertions;
using Xunit;
using Microsoft.DotNet.Cli.Build;
namespace EndToEnd
{
public class GenerateDefaultRuntimeFrameworkVersionTests
{
[Theory]
[InlineData("3.0.0-rtm", "3.0.0-rtm")]
[InlineData("3.1.0", "3.1.0")]
[InlineData("10.3.10", "10.3.0")]
[InlineData("1.1.10-prerelease", "1.1.0")]
public void ItGeneratesDefaultVersionBasedOnRuntimePackVersion(string runtimePackVersion, string defaultRuntimeFrameworkVersion)
{
var generateTask = new GenerateDefaultRuntimeFrameworkVersion()
{
RuntimePackVersion = runtimePackVersion
};
generateTask
.Execute()
.Should().BeTrue();
generateTask.DefaultRuntimeFrameworkVersion.Should().Be(defaultRuntimeFrameworkVersion);
}
}
}