diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.DefaultItems.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.DefaultItems.targets
index 02192d06a92b..77d3d1245415 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.DefaultItems.targets
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.DefaultItems.targets
@@ -55,7 +55,7 @@ Copyright (c) .NET Foundation. All rights reserved.
+
+
+ 1.0.6
+ 1.1.3
+
-
-
-
- 1.0.5
- 1.1.2
-
-
- $(_TargetFrameworkVersionWithoutV)
+
+
+
+
+
+
+
+ 1.0.5
+ $(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0)
+
+
+
+
+ 1.1.2
+ $(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1)
+
+
+
+
+
+
+ $(_TargetFrameworkVersionWithoutV)
+ $(_TargetFrameworkVersionWithoutV)
+
+
+
+
+ $(ImplicitRuntimeFrameworkVersionForSelfContainedApp)
+ $(ImplicitRuntimeFrameworkVersionForFrameworkDependentApp)
diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs
index 957416415ac7..da150715834a 100644
--- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs
+++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs
@@ -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();
- 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();
+ actualRuntimeFrameworkVersion.Should().Be(expectedRuntimeVersion);
+ }
- string actualRuntimeFrameworkVersion = ((JValue)runtimeConfig["runtimeOptions"]["framework"]["version"]).Value();
- 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);
diff --git a/test/Microsoft.NET.TestFramework/Commands/MSBuildTest.cs b/test/Microsoft.NET.TestFramework/Commands/MSBuildTest.cs
index 66b1884912d2..1b1686c37af5 100644
--- a/test/Microsoft.NET.TestFramework/Commands/MSBuildTest.cs
+++ b/test/Microsoft.NET.TestFramework/Commands/MSBuildTest.cs
@@ -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;
}
}
diff --git a/test/Microsoft.NET.TestFramework/Commands/TestCommand.cs b/test/Microsoft.NET.TestFramework/Commands/TestCommand.cs
index b2b598032f9c..2dfdf4bb3609 100644
--- a/test/Microsoft.NET.TestFramework/Commands/TestCommand.cs
+++ b/test/Microsoft.NET.TestFramework/Commands/TestCommand.cs
@@ -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);
}
diff --git a/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs b/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs
index 41ff16e11d3b..999b1ac00223 100644
--- a/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs
+++ b/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs
@@ -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; }
@@ -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
diff --git a/test/Microsoft.NET.TestFramework/RepoInfo.cs b/test/Microsoft.NET.TestFramework/RepoInfo.cs
index e443d37a29c9..8d828838c477 100644
--- a/test/Microsoft.NET.TestFramework/RepoInfo.cs
+++ b/test/Microsoft.NET.TestFramework/RepoInfo.cs
@@ -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