From 82ff6397f5d3bf58bd59e133346b9be768852348 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Tue, 1 Nov 2016 14:11:11 -0700 Subject: [PATCH 1/2] Migrating unqualifing references as projects if we find a matching project. Without this, we have project references being migrated as package references. --- .../ProjectA/.noautobuild | 0 .../ProjectA/Program.cs | 19 ++++++++++++ .../ProjectA/project.json | 27 ++++++++++++++++ .../ProjectB/.noautobuild | 0 .../ProjectB/Helper.cs | 15 +++++++++ .../ProjectB/project.json | 18 +++++++++++ .../ProjectDependencyFinder.cs | 3 +- ...enThatIWantToMigrateProjectDependencies.cs | 31 +++++++++++++++---- 8 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/.noautobuild create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/Program.cs create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/project.json create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/.noautobuild create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/Helper.cs create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/project.json 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; } } } From 23a44f192f5556d9b01a04d23c6107d0d4022192 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Tue, 1 Nov 2016 14:58:11 -0700 Subject: [PATCH 2/2] Fixing the test on windows. We need to use path.combine because of the forward/backward slashes for directory separation. --- .../Rules/GivenThatIWantToMigrateProjectDependencies.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs index 13648ef0e..b6aa8915a 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs @@ -253,9 +253,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests public void It_migrates_unqualified_dependencies_as_ProjectReference_when_a_matching_project_is_found() { var mockProj = MigrateProject("TestAppWithUnqualifiedDependencies", "ProjectA"); + var projectReferenceInclude = Path.Combine("..", "ProjectB", "ProjectB.csproj"); var projectReferences = mockProj.Items.Should().ContainSingle( - item => item.ItemType == "ProjectReference" && item.Include == "../ProjectB/ProjectB.csproj"); + item => item.ItemType == "ProjectReference" && item.Include == projectReferenceInclude); } private ProjectRootElement MigrateProject(string solution, string project)