Migration: Do not add RIDs for Library projects (#5279)

* WIP

* Do not add runtime identifiers for libraries

* Reusing an existing test project

* Fix up tests
This commit is contained in:
Justin Goshi 2017-01-11 15:05:12 -10:00 committed by Piotr Puszkiewicz
parent 0bd6303f47
commit 03be0e56d4
10 changed files with 134 additions and 3 deletions

View file

@ -0,0 +1,12 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -0,0 +1,20 @@
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NetCore.App": {
"version": "1.0.3",
"type": "platform"
}
}
},
"net20": {},
"net35": {},
"net40": {},
"net461": {}
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace Library
{
public class TestLib
{
public static void Test()
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -0,0 +1,16 @@
{
"version": "1.0.0-*",
"frameworks": {
"netstandard1.6": {
"dependencies": {
"NETStandard.Library": "1.6"
}
},
"netstandard1.3": {
"dependencies": {
"NETStandard.Library": "1.3"
}
},
"net451": {}
}
}

View file

@ -38,9 +38,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration
return projectContexts.Any(p => p.IsFullFramework());
}
public static bool HasExeOutput(this IEnumerable<ProjectContext> projectContexts)
{
return projectContexts.Any(p => p.IsExe());
}
public static bool HasLibraryOutput(this IEnumerable<ProjectContext> projectContexts)
{
return projectContexts.Any(p => p.IsLibrary());
}
public static bool IsFullFramework(this ProjectContext projectContext)
{
return !projectContext.TargetFramework.IsPackageBased;
}
public static bool IsExe(this ProjectContext projectContext)
{
var compilerOptions = projectContext.ProjectFile.GetCompilerOptions(null, null);
return (compilerOptions.EmitEntryPoint != null && compilerOptions.EmitEntryPoint.Value);
}
public static bool IsLibrary(this ProjectContext projectContext)
{
var compilerOptions = projectContext.ProjectFile.GetCompilerOptions(null, null);
return (compilerOptions.EmitEntryPoint == null || !compilerOptions.EmitEntryPoint.Value);
}
}
}

View file

@ -133,13 +133,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
"RuntimeIdentifiers",
projectContexts => RuntimeIdentifiers,
projectContexts => !projectContexts.HasRuntimes() &&
!projectContexts.HasLibraryOutput() &&
projectContexts.HasBothCoreAndFullFrameworkTFMs());
private AddPropertyTransform<IEnumerable<ProjectContext>> RuntimeIdentifierTransform =>
new AddPropertyTransform<IEnumerable<ProjectContext>>(
"RuntimeIdentifier",
projectContexts => "win7-x86",
projectContexts => !projectContexts.HasRuntimes() && projectContexts.HasFullFrameworkTFM())
projectContexts => !projectContexts.HasRuntimes() &&
!projectContexts.HasLibraryOutput() &&
projectContexts.HasFullFrameworkTFM())
.WithMSBuildCondition(projectContexts =>
{
string msBuildCondition = null;

View file

@ -73,7 +73,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("TestLibraryWithMultipleFrameworks")
.FromTestAssetBase("PJAppWithMultipleFrameworks")
.SaveToDisk(testDirectory);
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
@ -98,7 +98,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("TestLibraryWithMultipleFrameworks")
.FromTestAssetBase("PJAppWithMultipleFrameworks")
.SaveToDisk(testDirectory);
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
@ -197,5 +197,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
mockProj.Properties.Count(p => p.Name == "TargetFramework").Should().Be(1);
}
[Fact]
public void MigratingLibWithMultipleTFMsDoesNotAddRuntimes()
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("PJLibWithMultipleFrameworks")
.SaveToDisk(testDirectory);
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
var mockProj = ProjectRootElement.Create();
var migrationSettings =
MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
var migrationInputs = new MigrationRuleInputs(
projectContexts,
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
var reason = "Should not add runtime identifiers for libraries";
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0, reason);
mockProj.Properties.Count(p => p.Name == "RuntimeIdentifier").Should().Be(0, reason);
}
}
}

View file

@ -202,6 +202,26 @@ namespace Microsoft.DotNet.Migration.Tests
outputsIdentical.Should().BeTrue();
}
[WindowsOnlyFact]
public void ItMigratesLibraryWithMultipleTFMsAndFullFramework()
{
var projectName = "PJLibWithMultipleFrameworks";
var projectDirectory =
TestAssetsManager.CreateTestInstance(projectName, identifier: projectName).WithLockFiles().Path;
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, projectName);
var outputsIdentical =
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
if (!outputsIdentical)
{
OutputDiagnostics(outputComparisonData);
}
outputsIdentical.Should().BeTrue();
}
[Theory]
[InlineData("TestAppWithLibrary/TestLibrary")]
[InlineData("TestLibraryWithAnalyzer")]