From 6a72ec603ed9833cb2f34228b4c180823ff3df4c Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Tue, 31 Jan 2017 15:27:22 -0800 Subject: [PATCH] Changing the order in which search paths are added for migration and setting the project file path in the ProjectDependency appropriately in the case of csproj and project.json --- .../{test => }/ProjectB/Program.cs | 0 .../{test => }/ProjectB/project.json | 0 .../PJHalfMigrated/global.json | 2 +- .../ProjectDependencyFinder.cs | 11 +++++++--- ...enThatIWantToMigrateProjectDependencies.cs | 21 +++++++++++++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) rename TestAssets/NonRestoredTestProjects/PJHalfMigrated/{test => }/ProjectB/Program.cs (100%) rename TestAssets/NonRestoredTestProjects/PJHalfMigrated/{test => }/ProjectB/project.json (100%) diff --git a/TestAssets/NonRestoredTestProjects/PJHalfMigrated/test/ProjectB/Program.cs b/TestAssets/NonRestoredTestProjects/PJHalfMigrated/ProjectB/Program.cs similarity index 100% rename from TestAssets/NonRestoredTestProjects/PJHalfMigrated/test/ProjectB/Program.cs rename to TestAssets/NonRestoredTestProjects/PJHalfMigrated/ProjectB/Program.cs diff --git a/TestAssets/NonRestoredTestProjects/PJHalfMigrated/test/ProjectB/project.json b/TestAssets/NonRestoredTestProjects/PJHalfMigrated/ProjectB/project.json similarity index 100% rename from TestAssets/NonRestoredTestProjects/PJHalfMigrated/test/ProjectB/project.json rename to TestAssets/NonRestoredTestProjects/PJHalfMigrated/ProjectB/project.json diff --git a/TestAssets/NonRestoredTestProjects/PJHalfMigrated/global.json b/TestAssets/NonRestoredTestProjects/PJHalfMigrated/global.json index d93eeb709..b0323e428 100644 --- a/TestAssets/NonRestoredTestProjects/PJHalfMigrated/global.json +++ b/TestAssets/NonRestoredTestProjects/PJHalfMigrated/global.json @@ -1,3 +1,3 @@ { - "projects": [ "src", "test" ] + "projects": [ "src" ] } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs index d8332258a..976cc8502 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs @@ -230,10 +230,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration projectSearchPaths.Add(projectRootDirectory); var globalPaths = GetGlobalPaths(projectRootDirectory); - projectSearchPaths = projectSearchPaths.Union(globalPaths).ToList(); + projectSearchPaths = globalPaths.Union(projectSearchPaths).ToList(); var solutionPaths = GetSolutionPaths(slnFile); - projectSearchPaths = projectSearchPaths.Union(solutionPaths).ToList(); + projectSearchPaths = solutionPaths.Union(projectSearchPaths).ToList(); var projects = new Dictionary(StringComparer.Ordinal); @@ -328,11 +328,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration var projectJSONFilePath = Path.Combine(projectDirectory.FullName, "project.json"); var csProjFilePath = Path.Combine(projectDirectory.FullName, $"{projectDirectory.Name}.csproj"); - if (File.Exists(projectJSONFilePath) || File.Exists(csProjFilePath)) + if (File.Exists(projectJSONFilePath)) { var project = new ProjectDependency(projectDirectory.Name, projectJSONFilePath); projects.Add(project); } + else if (File.Exists(csProjFilePath)) + { + var project = new ProjectDependency(projectDirectory.Name, csProjFilePath); + projects.Add(project); + } } internal static List GetGlobalPaths(string rootPath) diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs index 028bda3a8..d8c64688f 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs @@ -302,6 +302,27 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests item => item.ItemType == "ProjectReference" && item.Include == projectReferenceInclude); } + [Fact] + public void ItDoesNotReferenceTheProjectUnderBackupWhenMigratingAPartiallyMigratedStructure() + { + var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects"); + var solutionDirectory = testAssetsManager.CreateTestInstance("PJHalfMigrated").Path; + + var appDirectory = Path.Combine(solutionDirectory, "ProjectB"); + + var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); + var mockProj = ProjectRootElement.Create(); + var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, 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().ContainSingle(); + projectReferences.Single().Include.Should().Be("../src/ProjectA/ProjectA.csproj"); + } + private ProjectRootElement MigrateProject(string solution, string project) { return MigrateProject(solution, project, FrameworkConstants.CommonFrameworks.NetCoreApp10);