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:
parent
0bd6303f47
commit
03be0e56d4
10 changed files with 134 additions and 3 deletions
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ConsoleApplication
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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": {}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Library
|
||||||
|
{
|
||||||
|
public class TestLib
|
||||||
|
{
|
||||||
|
public static void Test()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.0-*",
|
||||||
|
"frameworks": {
|
||||||
|
"netstandard1.6": {
|
||||||
|
"dependencies": {
|
||||||
|
"NETStandard.Library": "1.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"netstandard1.3": {
|
||||||
|
"dependencies": {
|
||||||
|
"NETStandard.Library": "1.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"net451": {}
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,9 +38,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
return projectContexts.Any(p => p.IsFullFramework());
|
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)
|
public static bool IsFullFramework(this ProjectContext projectContext)
|
||||||
{
|
{
|
||||||
return !projectContext.TargetFramework.IsPackageBased;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,13 +133,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
"RuntimeIdentifiers",
|
"RuntimeIdentifiers",
|
||||||
projectContexts => RuntimeIdentifiers,
|
projectContexts => RuntimeIdentifiers,
|
||||||
projectContexts => !projectContexts.HasRuntimes() &&
|
projectContexts => !projectContexts.HasRuntimes() &&
|
||||||
|
!projectContexts.HasLibraryOutput() &&
|
||||||
projectContexts.HasBothCoreAndFullFrameworkTFMs());
|
projectContexts.HasBothCoreAndFullFrameworkTFMs());
|
||||||
|
|
||||||
private AddPropertyTransform<IEnumerable<ProjectContext>> RuntimeIdentifierTransform =>
|
private AddPropertyTransform<IEnumerable<ProjectContext>> RuntimeIdentifierTransform =>
|
||||||
new AddPropertyTransform<IEnumerable<ProjectContext>>(
|
new AddPropertyTransform<IEnumerable<ProjectContext>>(
|
||||||
"RuntimeIdentifier",
|
"RuntimeIdentifier",
|
||||||
projectContexts => "win7-x86",
|
projectContexts => "win7-x86",
|
||||||
projectContexts => !projectContexts.HasRuntimes() && projectContexts.HasFullFrameworkTFM())
|
projectContexts => !projectContexts.HasRuntimes() &&
|
||||||
|
!projectContexts.HasLibraryOutput() &&
|
||||||
|
projectContexts.HasFullFrameworkTFM())
|
||||||
.WithMSBuildCondition(projectContexts =>
|
.WithMSBuildCondition(projectContexts =>
|
||||||
{
|
{
|
||||||
string msBuildCondition = null;
|
string msBuildCondition = null;
|
||||||
|
|
|
@ -73,7 +73,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
{
|
{
|
||||||
var testDirectory = Temp.CreateDirectory().Path;
|
var testDirectory = Temp.CreateDirectory().Path;
|
||||||
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
|
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
|
||||||
.FromTestAssetBase("TestLibraryWithMultipleFrameworks")
|
.FromTestAssetBase("PJAppWithMultipleFrameworks")
|
||||||
.SaveToDisk(testDirectory);
|
.SaveToDisk(testDirectory);
|
||||||
|
|
||||||
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
|
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
|
||||||
|
@ -98,7 +98,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
{
|
{
|
||||||
var testDirectory = Temp.CreateDirectory().Path;
|
var testDirectory = Temp.CreateDirectory().Path;
|
||||||
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
|
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
|
||||||
.FromTestAssetBase("TestLibraryWithMultipleFrameworks")
|
.FromTestAssetBase("PJAppWithMultipleFrameworks")
|
||||||
.SaveToDisk(testDirectory);
|
.SaveToDisk(testDirectory);
|
||||||
|
|
||||||
var projectContexts = ProjectContext.CreateContextForEachFramework(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);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,6 +202,26 @@ namespace Microsoft.DotNet.Migration.Tests
|
||||||
outputsIdentical.Should().BeTrue();
|
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]
|
[Theory]
|
||||||
[InlineData("TestAppWithLibrary/TestLibrary")]
|
[InlineData("TestAppWithLibrary/TestLibrary")]
|
||||||
[InlineData("TestLibraryWithAnalyzer")]
|
[InlineData("TestLibraryWithAnalyzer")]
|
||||||
|
|
Loading…
Reference in a new issue