Migrating unqualifing references as projects if we find a matching project. Without this, we have project references being migrated as package references.
This commit is contained in:
parent
ad7c462956
commit
82ff6397f5
8 changed files with 106 additions and 7 deletions
|
@ -0,0 +1,19 @@
|
|||
// 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;
|
||||
using TestLibrary;
|
||||
|
||||
namespace TestApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("This string came from ProjectA");
|
||||
Console.WriteLine($"{ProjectB.GetMessage()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"emitEntryPoint": true,
|
||||
"preserveCompilationContext": true
|
||||
},
|
||||
"dependencies": {
|
||||
"ProjectB": "1.0.0-*",
|
||||
"Microsoft.NETCore.App": "1.0.1"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.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,15 @@
|
|||
// 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 ProjectB
|
||||
{
|
||||
public static string GetMessage()
|
||||
{
|
||||
return "This string came from ProjectB";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"nowarn": [
|
||||
"CS1591"
|
||||
],
|
||||
"xmlDoc": true,
|
||||
"additionalArguments": [
|
||||
"-highentropyva+"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.6.0"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {}
|
||||
}
|
||||
}
|
|
@ -98,7 +98,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
|
||||
foreach (var projectFileDependency in
|
||||
projectFileDependenciesForFramework.Where(p =>
|
||||
p.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project))
|
||||
p.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project ||
|
||||
p.LibraryRange.TypeConstraint == LibraryDependencyTarget.All))
|
||||
{
|
||||
var dependencyName = projectFileDependency.Name;
|
||||
|
||||
|
|
|
@ -242,10 +242,28 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
[Fact]
|
||||
public void It_promotes_P2P_references_up_in_the_dependency_chain()
|
||||
{
|
||||
var solutionDirectory =
|
||||
TestAssetsManager.CreateTestInstance("TestAppDependencyGraph", callingMethod: "p").Path;
|
||||
var mockProj = MigrateProject("TestAppDependencyGraph", "ProjectA");
|
||||
|
||||
var appDirectory = Path.Combine(solutionDirectory, "ProjectA");
|
||||
var projectReferences = mockProj.Items.Where(
|
||||
item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));
|
||||
projectReferences.Count().Should().Be(7);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_migrates_unqualified_dependencies_as_ProjectReference_when_a_matching_project_is_found()
|
||||
{
|
||||
var mockProj = MigrateProject("TestAppWithUnqualifiedDependencies", "ProjectA");
|
||||
|
||||
var projectReferences = mockProj.Items.Should().ContainSingle(
|
||||
item => item.ItemType == "ProjectReference" && item.Include == "../ProjectB/ProjectB.csproj");
|
||||
}
|
||||
|
||||
private ProjectRootElement MigrateProject(string solution, string project)
|
||||
{
|
||||
var solutionDirectory =
|
||||
TestAssetsManager.CreateTestInstance(solution, callingMethod: "p").Path;
|
||||
|
||||
var appDirectory = Path.Combine(solutionDirectory, project);
|
||||
|
||||
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
|
||||
var mockProj = ProjectRootElement.Create();
|
||||
|
@ -254,9 +272,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
mockProj.AddPropertyGroup());
|
||||
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
|
||||
|
||||
var projectReferences = mockProj.Items.Where(
|
||||
item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));
|
||||
projectReferences.Count().Should().Be(7);
|
||||
var s = mockProj.Items.Select(p => $"ItemType = {p.ItemType}, Include = {p.Include}");
|
||||
Console.WriteLine(string.Join(Environment.NewLine, s));
|
||||
|
||||
return mockProj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue