From cdf91f2f30a26ea593aa7acc6c42d23b5856a29c Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Thu, 19 Jan 2017 10:32:32 -0800 Subject: [PATCH] Fixing dotnet migrate global.json. This was failing because we were turning global.json into an empty string and trying to construct a directory for it. The fix was to detect this and transform it into a . directory. Migrate is already respecting the projects node in global.json. --- .../TestAsset}/.noautobuild | 0 .../TestAssets/TestAsset/Program.cs | 12 ++++++ .../TestAssets/TestAsset/project.json | 15 +++++++ .../global.json | 4 +- .../{ => src}/App/.noautobuild | 0 .../{ => src}/App/project.json | 0 .../test/App.Tests/.noautobuild | 0 .../App.Tests/EntityFramework/Program.cs | 0 .../{ => test}/App.Tests/project.json | 0 .../commands/dotnet-migrate/MigrateCommand.cs | 18 +++++--- ...enThatIWantToMigrateAppsUsingGlobalJson.cs | 42 +++++++++++++++++++ 11 files changed, 83 insertions(+), 8 deletions(-) rename TestAssets/TestProjects/AppWithPackageNamedAfterFolder/{App.Tests => TestAssets/TestAsset}/.noautobuild (100%) create mode 100644 TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/Program.cs create mode 100644 TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/project.json rename TestAssets/TestProjects/AppWithPackageNamedAfterFolder/{ => src}/App/.noautobuild (100%) rename TestAssets/TestProjects/AppWithPackageNamedAfterFolder/{ => src}/App/project.json (100%) create mode 100644 TestAssets/TestProjects/AppWithPackageNamedAfterFolder/test/App.Tests/.noautobuild rename TestAssets/TestProjects/AppWithPackageNamedAfterFolder/{ => test}/App.Tests/EntityFramework/Program.cs (100%) rename TestAssets/TestProjects/AppWithPackageNamedAfterFolder/{ => test}/App.Tests/project.json (100%) create mode 100644 test/dotnet-migrate.Tests/GivenThatIWantToMigrateAppsUsingGlobalJson.cs diff --git a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App.Tests/.noautobuild b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/.noautobuild similarity index 100% rename from TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App.Tests/.noautobuild rename to TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/.noautobuild diff --git a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/Program.cs b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/Program.cs new file mode 100644 index 000000000..7d1e94271 --- /dev/null +++ b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace App.Tests +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World from Test asset!"); + } + } +} diff --git a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/project.json b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/project.json new file mode 100644 index 000000000..91b0a9ae6 --- /dev/null +++ b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/TestAssets/TestAsset/project.json @@ -0,0 +1,15 @@ +{ + "frameworks": { + "netcoreapp1.0": { + "imports": [ + "portable-net451+win8" + ], + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.0", + "type": "platform" + } + } + } + } +} \ No newline at end of file diff --git a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/global.json b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/global.json index 7fd78b278..3427cd57d 100644 --- a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/global.json +++ b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/global.json @@ -1,6 +1,6 @@ { "projects": [ - "App", - "App.Tests" + "src", + "test" ] } diff --git a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App/.noautobuild b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/src/App/.noautobuild similarity index 100% rename from TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App/.noautobuild rename to TestAssets/TestProjects/AppWithPackageNamedAfterFolder/src/App/.noautobuild diff --git a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App/project.json b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/src/App/project.json similarity index 100% rename from TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App/project.json rename to TestAssets/TestProjects/AppWithPackageNamedAfterFolder/src/App/project.json diff --git a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/test/App.Tests/.noautobuild b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/test/App.Tests/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App.Tests/EntityFramework/Program.cs b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/test/App.Tests/EntityFramework/Program.cs similarity index 100% rename from TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App.Tests/EntityFramework/Program.cs rename to TestAssets/TestProjects/AppWithPackageNamedAfterFolder/test/App.Tests/EntityFramework/Program.cs diff --git a/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App.Tests/project.json b/TestAssets/TestProjects/AppWithPackageNamedAfterFolder/test/App.Tests/project.json similarity index 100% rename from TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App.Tests/project.json rename to TestAssets/TestProjects/AppWithPackageNamedAfterFolder/test/App.Tests/project.json diff --git a/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs b/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs index 9a61d3a3e..bb52cb4d4 100644 --- a/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs +++ b/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs @@ -364,12 +364,7 @@ namespace Microsoft.DotNet.Tools.Migrate private IEnumerable GetProjectsFromGlobalJson(string globalJson) { - if (!File.Exists(globalJson)) - { - throw new GracefulException($"Unable to find global settings file at {globalJson}"); - } - - var searchPaths = ProjectDependencyFinder.GetGlobalPaths(Path.GetDirectoryName(globalJson)); + var searchPaths = ProjectDependencyFinder.GetGlobalPaths(GetGlobalJsonDirectory(globalJson)); foreach (var searchPath in searchPaths) { @@ -392,6 +387,17 @@ namespace Microsoft.DotNet.Tools.Migrate } } + private string GetGlobalJsonDirectory(string globalJson) + { + if (!File.Exists(globalJson)) + { + throw new GracefulException($"Unable to find global settings file at {globalJson}"); + } + + var globalJsonDirectory = Path.GetDirectoryName(globalJson); + return string.IsNullOrEmpty(globalJsonDirectory) ? "." : globalJsonDirectory; + } + private IEnumerable GetProjectsFromSolution(string slnPath) { if (!File.Exists(slnPath)) diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateAppsUsingGlobalJson.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateAppsUsingGlobalJson.cs new file mode 100644 index 000000000..60b73dbfd --- /dev/null +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateAppsUsingGlobalJson.cs @@ -0,0 +1,42 @@ +// 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 FluentAssertions; +using Microsoft.DotNet.TestFramework; +using Microsoft.DotNet.Tools.Test.Utilities; +using System.IO; +using Xunit; + +namespace Microsoft.DotNet.Migration.Tests +{ + public class GivenThatIWantToMigrateAppsUsingGlobalJson : TestBase + { + [Fact] + public void ItMigratesWhenBeingPassedAFullPathToGlobalJson() + { + var solutionDirectory = + TestAssetsManager.CreateTestInstance("AppWithPackageNamedAfterFolder").Path; + var globalJsonPath = Path.Combine(solutionDirectory, "global.json"); + + new TestCommand("dotnet") + .WithForwardingToConsole() + .Execute($"migrate {globalJsonPath}") + .Should() + .Pass(); + } + + [Fact] + public void ItMigratesWhenBeingPassedJustGlobalJson() + { + var solutionDirectory = + TestAssetsManager.CreateTestInstance("AppWithPackageNamedAfterFolder").Path; + + new TestCommand("dotnet") + .WithWorkingDirectory(solutionDirectory) + .WithForwardingToConsole() + .Execute($"migrate global.json") + .Should() + .Pass(); + } + } +} \ No newline at end of file