From 175eaeb5c1a53efb3cb404fcf6ea6c50f733386f Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Mon, 24 Oct 2016 16:25:57 -0700 Subject: [PATCH] When determining the P2P dependencies, only use dependencies of type project. This prevents us from migrating a package dependency as a project dependency because of a project with the same name being present. --- .../TestApp/Program.cs | 12 ++++++++ .../TestApp/project.json | 29 +++++++++++++++++++ .../TestLibraryAsAPackage/.noautobuild | 0 .../TestLibraryAsAPackage/Helper.cs | 24 +++++++++++++++ .../TestLibraryAsAPackage/project.json | 18 ++++++++++++ .../global.json | 3 ++ .../ProjectDependencyFinder.cs | 7 +++-- ...enThatIWantToMigrateProjectDependencies.cs | 22 ++++++++++++++ 8 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestApp/Program.cs create mode 100644 TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestApp/project.json create mode 100644 TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/.noautobuild create mode 100644 TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/Helper.cs create mode 100644 TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/project.json create mode 100644 TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/global.json diff --git a/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestApp/Program.cs b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestApp/Program.cs new file mode 100644 index 000000000..24b0cd5f1 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestApp/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestApp/project.json b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestApp/project.json new file mode 100644 index 000000000..b748d3b9f --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestApp/project.json @@ -0,0 +1,29 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "emitEntryPoint": true + }, + "dependencies": { + "Microsoft.NETCore.App": "1.0.1", + "TestLibraryAsAPackage": { + "version": "1.0.0", + "target": "package" + } + }, + "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/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/.noautobuild b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/Helper.cs b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/Helper.cs new file mode 100644 index 000000000..8c643796b --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/Helper.cs @@ -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 + { + /// + /// Gets the message from the helper. This comment is here to help test XML documentation file generation, please do not remove it. + /// + /// A message + public static string GetMessage() + { + return "This string came from the test library!"; + } + + public static void SayHi() + { + Console.WriteLine("Hello there!"); + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/project.json b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/project.json new file mode 100644 index 000000000..48bc772d8 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/TestLibraryAsAPackage/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/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/global.json b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/global.json new file mode 100644 index 000000000..8c0927574 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/AppWithProjectDependencyAsTarget/global.json @@ -0,0 +1,3 @@ +{ + "projects": [ "." ] +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs index 5a29e7583..c92bec3a7 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs @@ -66,7 +66,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration projectFileDependenciesForFramework = project.GetTargetFramework(framework).Dependencies; } - foreach (var projectFileDependency in projectFileDependenciesForFramework) + foreach (var projectFileDependency in + projectFileDependenciesForFramework.Where(p => + p.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project)) { var dependencyName = projectFileDependency.Name; @@ -105,7 +107,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration FindPossibleProjectDependencies(projectContext.ProjectFile.ProjectFilePath); var projectDependencies = new List(); - foreach (var projectExport in projectExports) + foreach (var projectExport in + projectExports.Where(p => p.Library.Identity.Type == LibraryType.Project)) { var projectExportName = projectExport.Library.Identity.Name; ProjectDependency projectDependency; diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs index c077727fb..1ac3ed10a 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs @@ -1,6 +1,7 @@ using Microsoft.Build.Construction; using Microsoft.DotNet.ProjectJsonMigration; using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; using NuGet.Frameworks; using System; @@ -39,6 +40,27 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests projectReference.Parent.Condition.Should().BeEmpty(); } + [Fact] + public void It_does_not_migrate_a_dependency_with_target_package_that_has_a_matching_project_as_a_ProjectReference() + { + var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects"); + var solutionDirectory = + testAssetsManager.CreateTestInstance("AppWithProjectDependencyAsTarget", 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.Should().BeEmpty(); + } + [Fact] public void TFM_specific_Project_dependencies_are_migrated_to_ProjectReference_under_condition_ItemGroup() {