Fixing project dependencies migration so that they are only conditioned when they where under a TFM in the project.json to begin with.
This commit is contained in:
parent
caf072daeb
commit
be419e3b70
8 changed files with 157 additions and 12 deletions
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TestApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(TestLibrary.Helper.GetMessage());
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"emitEntryPoint": true,
|
||||
"preserveCompilationContext": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": "1.0.1"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"TestLibrary": {
|
||||
"target": "project",
|
||||
"version": "1.0.0-*"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"runtimes": {
|
||||
"win7-x64": {},
|
||||
"win7-x86": {},
|
||||
"osx.10.10-x64": {},
|
||||
"osx.10.11-x64": {},
|
||||
"ubuntu.14.04-x64": {},
|
||||
"ubuntu.16.04-x64": {},
|
||||
"centos.7-x64": {},
|
||||
"rhel.7.2-x64": {},
|
||||
"debian.8-x64": {},
|
||||
"fedora.23-x64": {},
|
||||
"opensuse.13.2-x64": {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace TestLibrary
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the message from the helper. This comment is here to help test XML documentation file generation, please do not remove it.
|
||||
/// </summary>
|
||||
/// <returns>A message</returns>
|
||||
public static string GetMessage()
|
||||
{
|
||||
return "This string came from the test library!";
|
||||
}
|
||||
|
||||
public static void SayHi()
|
||||
{
|
||||
Console.WriteLine("Hello there!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"nowarn": [
|
||||
"CS1591"
|
||||
],
|
||||
"xmlDoc": true,
|
||||
"additionalArguments": [
|
||||
"-highentropyva+"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.6.0"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"projects": [ "."]
|
||||
}
|
|
@ -79,21 +79,46 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
HashSet<string> migratedXProjDependencyNames,
|
||||
ProjectRootElement outputMSBuildProject)
|
||||
{
|
||||
if(projectContexts.Any())
|
||||
{
|
||||
MigrateProjectJsonProjectDependency(
|
||||
projectContexts.First().ProjectFile,
|
||||
null,
|
||||
migratedXProjDependencyNames,
|
||||
outputMSBuildProject);
|
||||
}
|
||||
|
||||
foreach (var projectContext in projectContexts)
|
||||
{
|
||||
var projectDependencies = _projectDependencyFinder.ResolveProjectDependencies(projectContext, migratedXProjDependencyNames);
|
||||
|
||||
var projectDependencyTransformResults = projectDependencies.Select(p => ProjectDependencyTransform.Transform(p));
|
||||
|
||||
if (projectDependencyTransformResults.Any())
|
||||
{
|
||||
AddProjectDependenciesToNewItemGroup(
|
||||
outputMSBuildProject.AddItemGroup(),
|
||||
projectDependencyTransformResults,
|
||||
projectContext.TargetFramework);
|
||||
}
|
||||
MigrateProjectJsonProjectDependency(
|
||||
projectContext.ProjectFile,
|
||||
projectContext.TargetFramework,
|
||||
migratedXProjDependencyNames,
|
||||
outputMSBuildProject);
|
||||
}
|
||||
}
|
||||
|
||||
private void MigrateProjectJsonProjectDependency(
|
||||
Project project,
|
||||
NuGetFramework framework,
|
||||
HashSet<string> migratedXProjDependencyNames,
|
||||
ProjectRootElement outputMSBuildProject)
|
||||
{
|
||||
var projectDependencies = _projectDependencyFinder.ResolveProjectDependenciesForFramework(
|
||||
project,
|
||||
framework,
|
||||
migratedXProjDependencyNames);
|
||||
|
||||
var projectDependencyTransformResults =
|
||||
projectDependencies.Select(p => ProjectDependencyTransform.Transform(p));
|
||||
|
||||
if (projectDependencyTransformResults.Any())
|
||||
{
|
||||
AddProjectDependenciesToNewItemGroup(
|
||||
outputMSBuildProject.AddItemGroup(),
|
||||
projectDependencyTransformResults,
|
||||
framework);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddProjectDependenciesToNewItemGroup(
|
||||
|
|
|
@ -34,7 +34,32 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
var projectReferences = mockProj.Items.Where(item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));
|
||||
projectReferences.Count().Should().Be(1);
|
||||
|
||||
projectReferences.First().Include.Should().Be(Path.Combine("..", "TestLibrary", "TestLibrary.csproj"));
|
||||
var projectReference = projectReferences.First();
|
||||
projectReference.Include.Should().Be(Path.Combine("..", "TestLibrary", "TestLibrary.csproj"));
|
||||
projectReference.Parent.Condition.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TFM_specific_Project_dependencies_are_migrated_to_ProjectReference_under_condition_ItemGroup()
|
||||
{
|
||||
var solutionDirectory =
|
||||
TestAssetsManager.CreateTestInstance("TestAppWithLibraryUnderTFM", callingMethod: "p").Path;
|
||||
|
||||
var appDirectory = Path.Combine(solutionDirectory, "TestApp");
|
||||
|
||||
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
|
||||
var mockProj = ProjectRootElement.Create();
|
||||
var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null);
|
||||
var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(),
|
||||
mockProj.AddPropertyGroup());
|
||||
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
|
||||
|
||||
var projectReferences = mockProj.Items.Where(item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));
|
||||
projectReferences.Count().Should().Be(1);
|
||||
|
||||
var projectReference = projectReferences.First();
|
||||
projectReference.Include.Should().Be(Path.Combine("..", "TestLibrary", "TestLibrary.csproj"));
|
||||
projectReference.Parent.Condition.Should().Be(" '$(TargetFramework)' == 'netcoreapp1.0' ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
Loading…
Reference in a new issue