Skip to content

Commit

Permalink
Add support for net5.0 TargetFramework
Browse files Browse the repository at this point in the history
Reapplies #10762 that was reverted because it went to the wrong branch.

This reverts commit 508463d.
  • Loading branch information
dsplaisted authored and nguerrera committed Mar 4, 2020
1 parent b66b13d commit 0f5fc4b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Layout/redist/minimumMSBuildVersion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.3.0
16.5.0
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ protected override void ExecuteCore()
string targetingPackDataPath = Path.Combine(targetingPackRoot, "data");

string targetingPackDllFolder = Path.Combine(targetingPackRoot, "ref", targetingPackTargetFramework);

// Fall back to netcoreapp5.0 folder if looking for net5.0 and it's not found
if (!Directory.Exists(targetingPackDllFolder) &&
targetingPackTargetFramework.Equals("net5.0", StringComparison.OrdinalIgnoreCase))
{
targetingPackTargetFramework = "netcoreapp5.0";
targetingPackDllFolder = Path.Combine(targetingPackRoot, "ref", targetingPackTargetFramework);
}

string platformManifestPath = Path.Combine(targetingPackDataPath, "PlatformManifest.txt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<_ShortFrameworkVersion>$(TargetFramework.Substring($(_ShortFrameworkIdentifier.Length)))</_ShortFrameworkVersion>
</PropertyGroup>

<!-- Map short name to long name. See earlier comment for example of how to work with identifiers that are not recognized here. -->
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == ''">
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'netstandard'">.NETStandard</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'netcoreapp'">.NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'net'">.NETFramework</TargetFrameworkIdentifier>
</PropertyGroup>

<!-- Versions with dots are taken as is and just given leading 'v'. -->
<PropertyGroup Condition="'$(TargetFrameworkVersion)' == '' and '$(_ShortFrameworkVersion)' != '' and $(_ShortFrameworkVersion.Contains('.'))">
<TargetFrameworkVersion>v$(_ShortFrameworkVersion)</TargetFrameworkVersion>
Expand All @@ -67,6 +60,20 @@ Copyright (c) .NET Foundation. All rights reserved.
<TargetFrameworkVersion Condition="$(_ShortFrameworkVersion.Length) == 2">v$(_ShortFrameworkVersion[0]).$(_ShortFrameworkVersion[1])</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="$(_ShortFrameworkVersion.Length) == 3">v$(_ShortFrameworkVersion[0]).$(_ShortFrameworkVersion[1]).$(_ShortFrameworkVersion[2])</TargetFrameworkVersion>
</PropertyGroup>

<!-- Map short name to long name. See earlier comment for example of how to work with identifiers that are not recognized here. -->
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == ''">
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'netstandard'">.NETStandard</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'netcoreapp'">.NETCoreApp</TargetFrameworkIdentifier>

<!-- The meaning of "net" as a short framework name depends on the version. If it's 4.x or less, it means .NETFramework.
If the version is 5.0 or higher, then "net" means .NET 5.0 and on, which is the evolution of .NET Core, and uses
the .NETCoreApp TargetFrameworkIdentifier. -->
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'net' And
$([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '5.0'))">.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'net' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0'))">.NETCoreApp</TargetFrameworkIdentifier>
</PropertyGroup>

<!--
Trigger an error if we're unable to infer the framework identifier and version.
Expand Down
4 changes: 4 additions & 0 deletions src/Tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<TestArgs>$(TestArgs) -testExecutionDirectory $(TestLocalToolExecutionFolder)</TestArgs>
</PropertyGroup>

<!-- Run "dotnet new" (which will just display usage and available templates) in order to print first time
use message so that it doesn't interfere with tests which check the output of commands. -->
<Exec Command="$(ArtifactsBinDir)redist\$(Configuration)\dotnet\dotnet new" />

<Exec Command="dotnet tool run $(ToolCommandName) -- $(TestArgs)"
WorkingDirectory="$(TestLocalToolFolder)"
EnvironmentVariables="DOTNET_CLI_HOME=$(DOTNET_CLI_HOME)"
Expand Down
48 changes: 48 additions & 0 deletions src/Tests/Microsoft.NET.Build.Tests/Net50Targeting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.NET.Build.Tests
{
public class Net50Targeting : SdkTest
{
public Net50Targeting(ITestOutputHelper log) : base(log)
{
}

[Fact(Skip="Need NuGet support for net5.0 TFM")]
public void Net50TargetFrameworkParsesAsNetCoreAppTargetFrameworkIdentifier()
{
var testProject = new TestProject()
{
Name = "Net5Test",
TargetFrameworks = "net5.0",
IsSdkProject = true
};

var testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name);

var buildCommand = new BuildCommand(Log, testAsset.TestRoot, testProject.Name);

buildCommand.Execute()
.Should()
.Pass();

var getValuesCommand = new GetValuesCommand(Log, testAsset.TestRoot, testProject.TargetFrameworks, "TargetFrameworkIdentifier");
getValuesCommand.Execute()
.Should()
.Pass();

getValuesCommand.GetValues().Should().BeEquivalentTo(".NETCoreApp");
}
}
}

0 comments on commit 0f5fc4b

Please sign in to comment.