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