diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/.noautobuild b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/Program.cs b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/Program.cs new file mode 100644 index 000000000..9576b17c4 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/Program.cs @@ -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; + } + } +} diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/project.json b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/project.json new file mode 100644 index 000000000..5287abb9b --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/project.json @@ -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": {} + } +} diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/.noautobuild b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/Helper.cs b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/Helper.cs new file mode 100644 index 000000000..5a986d891 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/Helper.cs @@ -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"; + } + } +} diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/project.json b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/project.json new file mode 100644 index 000000000..48bc772d8 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/project.json @@ -0,0 +1,18 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "nowarn": [ + "CS1591" + ], + "xmlDoc": true, + "additionalArguments": [ + "-highentropyva+" + ] + }, + "dependencies": { + "NETStandard.Library": "1.6.0" + }, + "frameworks": { + "netstandard1.5": {} + } +} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs index b82adcd2f..ab69f6cc0 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs @@ -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; diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs index 346d35434..13648ef0e 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs @@ -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; } } }