Skip to content

Bump default versions for self-contained apps (for 1.1.x) #1523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<!--
Determine the NetCoreImplicitPackageVersion and RuntimeFrameworkVersion when targeting .NET Core
Determine the RuntimeFrameworkVersion when targeting .NET Core

When targeting .NET Core, the TargetFramework is generally used to specify which version of the runtime to use.

Expand All @@ -64,30 +64,51 @@ Copyright (c) .NET Foundation. All rights reserved.

The framework version that is written to the runtimeconfig.json file is based on the actual resolved package version
of Microsoft.NETCore.App. This is to allow floating the verion number.


If RuntimeFrameworkVersion is not specified, the following logic applies

- Self-contained apps use the latest corresponding patch version (from when the SDK shipped)
- Framework-dependent app targeting netcoreapp1.0 and netcoreapp1.1 use v1.0.5 and v1.1.2, respectively
- This is done for compatibility with previous releases that bumped the self-contained and framework-dependent versions together.
-->
<!-- These properties are here as a test hook so that we can test with the versions bumped before the actual framework
builds are available. -->
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(RuntimeFrameworkVersion)' == ''">
<ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0
Condition="'$(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0)' == ''">1.0.6</ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0>
<ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1
Condition="'$(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1)' == ''">1.1.3</ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<!-- If targeting .NET Core, and the RuntimeFrameworkVersion is not specified, use the latest patch version of that runtime that we know about.

This ensures that if a self-contained app is published where RuntimeFrameworkVersion is not specified, the latest patch
version of the runtime (that the SDK knew about when it shipped) will be used.

This also will fix an issue where Microsoft.NETCore.App 1.1.0 included a version of the Microsoft.DiaSymReader.Native package
that was authored in such a way that Microsoft.DiaSymReader.Native.amd64.dll and Microsoft.DiaSymReader.Native.x86.dll would
be copied to the output folder. Using Microsoft.NETCore.App 1.1.1 fixes this, as it references an updated version of the
DiaSymReader package with the issue fixed. (See https://github.com/dotnet/corefx/issues/14627)

Using the latest patch version that the SDK knows about does mean that an update to the SDK could change the version of
the runtime that a project targets. In general, this should be OK. If a project wants to opt out of this, it can specify
the exact version of the runtime to use with the RuntimeFrameworkVersion property.
-->
<!-- If targeting netcoreapp1.1, and RuntimeFrameworkVersion is not specified, use version 1.1.1 -->
<RuntimeFrameworkVersion Condition="'$(RuntimeFrameworkVersion)' == '' And '$(_TargetFrameworkVersionWithoutV)' == '1.0'">1.0.5</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion Condition="'$(RuntimeFrameworkVersion)' == '' And '$(_TargetFrameworkVersionWithoutV)' == '1.1'">1.1.2</RuntimeFrameworkVersion>

<!-- Default to use the version of the framework runtime matching the target framework version-->
<RuntimeFrameworkVersion Condition="'$(RuntimeFrameworkVersion)' == ''">$(_TargetFrameworkVersionWithoutV)</RuntimeFrameworkVersion>
<!-- Select implicit runtime framework versions -->
<Choose>
<!-- If not targeting .NET Core, or if RuntimeFrameworkVersion is already set, do nothing -->
<When Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp' Or '$(RuntimeFrameworkVersion)' != ''" />

<When Condition="'$(_TargetFrameworkVersionWithoutV)' == '1.0'">
<PropertyGroup>
<ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>1.0.5</ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>
<ImplicitRuntimeFrameworkVersionForSelfContainedApp>$(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0)</ImplicitRuntimeFrameworkVersionForSelfContainedApp>
</PropertyGroup>
</When>
<When Condition="'$(_TargetFrameworkVersionWithoutV)' == '1.1'">
<PropertyGroup>
<ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>1.1.2</ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>
<ImplicitRuntimeFrameworkVersionForSelfContainedApp>$(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1)</ImplicitRuntimeFrameworkVersionForSelfContainedApp>
</PropertyGroup>
</When>

<!-- If not covered by the previous cases, use the target framework version for the implicit RuntimeFrameworkVersions -->
<Otherwise>
<PropertyGroup>
<ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>$(_TargetFrameworkVersionWithoutV)</ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>
<ImplicitRuntimeFrameworkVersionForSelfContainedApp>$(_TargetFrameworkVersionWithoutV)</ImplicitRuntimeFrameworkVersionForSelfContainedApp>
</PropertyGroup>
</Otherwise>
</Choose>
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(RuntimeFrameworkVersion)' == ''">
<RuntimeFrameworkVersion Condition="'$(RuntimeIdentifier)' != '' ">$(ImplicitRuntimeFrameworkVersionForSelfContainedApp)</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion Condition="'$(RuntimeIdentifier)' == '' ">$(ImplicitRuntimeFrameworkVersionForFrameworkDependentApp)</RuntimeFrameworkVersion>
</PropertyGroup>

<UsingTask TaskName="CheckForImplicitPackageReferenceOverrides" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
Expand Down
88 changes: 63 additions & 25 deletions test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,84 @@ public class GivenThatWeWantToBuildANetCoreApp : SdkTest
public void It_targets_the_right_shared_framework(string targetFramework, string runtimeFrameworkVersion,
string expectedPackageVersion, string expectedRuntimeVersion)
{
string testIdentifier = "SharedFrameworkTargeting_" + string.Join("_", targetFramework, runtimeFrameworkVersion ?? "null");

It_targets_the_right_framework(testIdentifier, targetFramework, runtimeFrameworkVersion,
selfContained: false, isExe: true,
expectedPackageVersion: expectedPackageVersion, expectedRuntimeVersion: expectedRuntimeVersion);
}

// Test behavior when implicit version differs for framework-dependent and self-contained apps
[Theory]
[InlineData("netcoreapp1.0", false, true, "1.0.5")]
[InlineData("netcoreapp1.0", true, true, RepoInfo.ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0)]
[InlineData("netcoreapp1.0", false, false, "1.0.5")]
[InlineData("netcoreapp1.1", false, true, "1.1.2")]
[InlineData("netcoreapp1.1", true, true, RepoInfo.ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1)]
[InlineData("netcoreapp1.1", false, false, "1.1.2")]
public void It_targets_the_right_framework_depending_on_output_type(string targetFramework, bool selfContained, bool isExe, string expectedFrameworkVersion)
{
string testIdentifier = "Framework_targeting_" + (isExe ? "App_" : "Lib_") + (selfContained ? "SelfContained" : "FrameworkDependent");

It_targets_the_right_framework(testIdentifier, targetFramework, null, selfContained, isExe, expectedFrameworkVersion, expectedFrameworkVersion);
}

private void It_targets_the_right_framework(
string testIdentifier,
string targetFramework,
string runtimeFrameworkVersion,
bool selfContained,
bool isExe,
string expectedPackageVersion,
string expectedRuntimeVersion,
string extraMSBuildArguments = null)
{
string runtimeIdentifier = null;
if (selfContained)
{
runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework);
}

var testProject = new TestProject()
{
Name = "SharedFrameworkTest",
Name = "FrameworkTargetTest",
TargetFrameworks = targetFramework,
RuntimeFrameworkVersion = runtimeFrameworkVersion,
IsSdkProject = true,
IsExe = true
IsExe = isExe,
RuntimeIdentifier = runtimeIdentifier
};

string testIdentifier = string.Join("_", targetFramework, runtimeFrameworkVersion ?? "null");
var extraArgs = extraMSBuildArguments?.Split(' ') ?? Array.Empty<string>();

var testAsset = _testAssetsManager.CreateTestProject(testProject, nameof(It_targets_the_right_shared_framework), testIdentifier);

testAsset = testAsset.WithProjectChanges(project =>
{
var ns = project.Root.Name.Namespace;
var propertyGroup = new XElement(ns + "PropertyGroup");
project.Root.Add(propertyGroup);

if (runtimeFrameworkVersion != null)
{
propertyGroup.Add(new XElement(ns + "RuntimeFrameworkVersion", runtimeFrameworkVersion));
}
});

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

var buildCommand = new BuildCommand(Stage0MSBuild, Path.Combine(testAsset.TestRoot, testProject.Name));

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

var outputDirectory = buildCommand.GetOutputDirectory(targetFramework);
string runtimeConfigFile = Path.Combine(outputDirectory.FullName, testProject.Name + ".runtimeconfig.json");
string runtimeConfigContents = File.ReadAllText(runtimeConfigFile);
JObject runtimeConfig = JObject.Parse(runtimeConfigContents);
var outputDirectory = buildCommand.GetOutputDirectory(targetFramework, runtimeIdentifier: runtimeIdentifier);
if (isExe)
{
// Self-contained apps don't write a framework version to the runtimeconfig, so only check this for framework-dependent apps
if (!selfContained)
{
string runtimeConfigFile = Path.Combine(outputDirectory.FullName, testProject.Name + ".runtimeconfig.json");
string runtimeConfigContents = File.ReadAllText(runtimeConfigFile);
JObject runtimeConfig = JObject.Parse(runtimeConfigContents);

string actualRuntimeFrameworkVersion = ((JValue)runtimeConfig["runtimeOptions"]["framework"]["version"]).Value<string>();
actualRuntimeFrameworkVersion.Should().Be(expectedRuntimeVersion);
}

string actualRuntimeFrameworkVersion = ((JValue)runtimeConfig["runtimeOptions"]["framework"]["version"]).Value<string>();
actualRuntimeFrameworkVersion.Should().Be(expectedRuntimeVersion);
var runtimeconfigDevFileName = testProject.Name + ".runtimeconfig.dev.json";
outputDirectory.Should()
.HaveFile(runtimeconfigDevFileName);
}

LockFile lockFile = LockFileUtilities.GetLockFile(Path.Combine(buildCommand.ProjectRootPath, "obj", "project.assets.json"), NullLogger.Instance);

Expand Down
4 changes: 4 additions & 0 deletions test/Microsoft.NET.TestFramework/Commands/MSBuildTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ private ICommand CreateCommand(params string[] args)

command = command.EnvironmentVariable("MSBuildSDKsPath", RepoInfo.SdksPath);

command = command
.EnvironmentVariable(nameof(RepoInfo.ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0), RepoInfo.ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0)
.EnvironmentVariable(nameof(RepoInfo.ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1), RepoInfo.ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1);

return command;
}
}
Expand Down
1 change: 1 addition & 0 deletions test/Microsoft.NET.TestFramework/Commands/TestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private string FindProjectFile(string relativePathToProject)

public virtual DirectoryInfo GetOutputDirectory(string targetFramework, string configuration = "Debug", string runtimeIdentifier = "")
{
runtimeIdentifier = runtimeIdentifier ?? "";
string output = Path.Combine(ProjectRootPath, "bin", configuration, targetFramework, runtimeIdentifier);
return new DirectoryInfo(output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class TestProject
// Applies to SDK Projects
public string TargetFrameworks { get; set; }

public string RuntimeFrameworkVersion { get; set; }

public string RuntimeIdentifier { get; set; }

// TargetFrameworkVersion applies to non-SDK projects
public string TargetFrameworkVersion { get; set; }

Expand Down Expand Up @@ -129,9 +133,14 @@ internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder)
propertyGroup.Add(new XElement(ns + "TargetFramework", this.TargetFrameworks));
}

if (this.IsExe && targetFrameworks.Any(identifier => GetShortTargetFrameworkIdentifier(identifier).Equals("net", StringComparison.OrdinalIgnoreCase)))
if (!string.IsNullOrEmpty(this.RuntimeFrameworkVersion))
{
propertyGroup.Add(new XElement(ns + "RuntimeFrameworkVersion", this.RuntimeFrameworkVersion));
}

if (!string.IsNullOrEmpty(this.RuntimeIdentifier))
{
propertyGroup.Add(new XElement(ns + "RuntimeIdentifier", "win7-x86"));
propertyGroup.Add(new XElement(ns + "RuntimeIdentifier", this.RuntimeIdentifier));
}

// Update SDK reference to the version under test
Expand Down
8 changes: 8 additions & 0 deletions test/Microsoft.NET.TestFramework/RepoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ private static string FindConfigurationInBasePath()
return new DirectoryInfo(GetBaseDirectory()).Parent.Name;
}

// For test purposes, override the implicit .NETCoreApp version for self-contained apps that to builds thare
// (1) different from the fixed framework-dependent defaults (1.0.5, 1.1.2, 2.0.0)
// (2) currently available on nuget.org
//
// This allows bumping the versions before builds without causing tests to fail.
public const string ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0 = "1.0.4";
public const string ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1 = "1.1.1";

private static string GetBaseDirectory()
{
#if NET451
Expand Down