From 1570e0fde49f2ac226a5061f44c76179a71747c0 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Mon, 3 Oct 2016 21:40:24 -0700 Subject: [PATCH] Moving the ProjectToolsCommandResolver to dotnet out of Cli.Utils because of the dependency on Microsoft.Build. Also added a EndToEnd test for tools ref using the MSBuildTestApp. --- .../MSBuildTestApp/MSBuildTestApp.csproj | 6 +++ src/Microsoft.DotNet.Cli.Utils/Command.cs | 23 ++++++++++- .../DefaultCommandResolverPolicy.cs | 8 +++- .../ICommandResolverPolicy.cs | 7 ++++ .../CommandResolver.cs | 23 ++++++++++- .../CommandResolution/DepsJsonBuilder.cs} | 6 +-- .../LockFilePathCalculator.cs | 21 +++++++--- .../LockFileTargetExtensions.cs | 2 +- .../CommandResolution}/NuGetUtils.cs | 2 +- .../ProjectToolsCommandResolver.cs | 8 ++-- .../ProjectToolsCommandResolverPolicy.cs | 18 +++++++++ .../ResourceAssemblyInfo.cs | 2 +- .../CommandResolution}/SingleProjectInfo.cs | 2 +- src/dotnet/Program.cs | 8 +++- test/EndToEnd/GivenDotNetUsesMSBuild.cs | 22 +++++++++++ .../GivenADefaultCommandResolver.cs | 3 +- .../project.json | 8 ++-- .../project.json | 2 +- .../GivenAProjectToolsCommandResolver.cs | 4 +- ...GivenAProjectToolsCommandResolverPolicy.cs | 39 +++++++++++++++++++ .../GivenThatDotNetRunsCommands.cs | 1 + 21 files changed, 186 insertions(+), 29 deletions(-) create mode 100644 src/Microsoft.DotNet.Cli.Utils/CommandResolution/ICommandResolverPolicy.cs rename src/{Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/DependencyContextBuilder.cs => dotnet/CommandResolution/DepsJsonBuilder.cs} (99%) rename src/{Microsoft.DotNet.Cli.Utils => dotnet}/CommandResolution/LockFilePathCalculator.cs (62%) rename src/{Microsoft.DotNet.Cli.Utils/DependencyContextBuilding => dotnet/CommandResolution}/LockFileTargetExtensions.cs (98%) rename src/{Microsoft.DotNet.Cli.Utils/DependencyContextBuilding => dotnet/CommandResolution}/NuGetUtils.cs (93%) rename src/{Microsoft.DotNet.Cli.Utils => dotnet}/CommandResolution/ProjectToolsCommandResolver.cs (96%) create mode 100644 src/dotnet/CommandResolution/ProjectToolsCommandResolverPolicy.cs rename src/{Microsoft.DotNet.Cli.Utils/DependencyContextBuilding => dotnet/CommandResolution}/ResourceAssemblyInfo.cs (90%) rename src/{Microsoft.DotNet.Cli.Utils/DependencyContextBuilding => dotnet/CommandResolution}/SingleProjectInfo.cs (93%) rename test/{Microsoft.DotNet.Cli.Utils.Tests => dotnet.Tests}/GivenAProjectToolsCommandResolver.cs (98%) create mode 100644 test/dotnet.Tests/GivenAProjectToolsCommandResolverPolicy.cs diff --git a/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj b/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj index fa85e7479..76636daba 100644 --- a/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj +++ b/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj @@ -21,5 +21,11 @@ + + + 1.0.0 + + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Cli.Utils/Command.cs b/src/Microsoft.DotNet.Cli.Utils/Command.cs index e0eee974e..1024efdb6 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Command.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Command.cs @@ -63,7 +63,28 @@ namespace Microsoft.DotNet.Cli.Utils string outputPath = null, string applicationName = null) { - var commandSpec = CommandResolver.TryResolveCommandSpec(commandName, + return Create( + new DefaultCommandResolverPolicy(), + commandName, + args, + framework, + configuration, + outputPath, + applicationName); + } + + public static Command Create( + ICommandResolverPolicy commandResolverPolicy, + string commandName, + IEnumerable args, + NuGetFramework framework = null, + string configuration = Constants.DefaultConfiguration, + string outputPath = null, + string applicationName = null) + { + var commandSpec = CommandResolver.TryResolveCommandSpec( + commandResolverPolicy, + commandName, args, framework, configuration: configuration, diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DefaultCommandResolverPolicy.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DefaultCommandResolverPolicy.cs index f7357af8e..689835f7c 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DefaultCommandResolverPolicy.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DefaultCommandResolverPolicy.cs @@ -2,8 +2,13 @@ using Microsoft.DotNet.PlatformAbstractions; namespace Microsoft.DotNet.Cli.Utils { - public class DefaultCommandResolverPolicy + public class DefaultCommandResolverPolicy : ICommandResolverPolicy { + public CompositeCommandResolver CreateCommandResolver() + { + return Create(); + } + public static CompositeCommandResolver Create() { var environment = new EnvironmentProvider(); @@ -37,7 +42,6 @@ namespace Microsoft.DotNet.Cli.Utils compositeCommandResolver.AddCommandResolver(new MuxerCommandResolver()); compositeCommandResolver.AddCommandResolver(new RootedCommandResolver()); - compositeCommandResolver.AddCommandResolver(new ProjectToolsCommandResolver(packagedCommandSpecFactory)); compositeCommandResolver.AddCommandResolver(new AppBaseDllCommandResolver()); compositeCommandResolver.AddCommandResolver( new AppBaseCommandResolver(environment, platformCommandSpecFactory)); diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ICommandResolverPolicy.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ICommandResolverPolicy.cs new file mode 100644 index 000000000..f7116df42 --- /dev/null +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ICommandResolverPolicy.cs @@ -0,0 +1,7 @@ +namespace Microsoft.DotNet.Cli.Utils +{ + public interface ICommandResolverPolicy + { + CompositeCommandResolver CreateCommandResolver(); + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolver.cs index d929c8cad..8b2b7db97 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolver.cs @@ -5,7 +5,7 @@ using NuGet.Frameworks; namespace Microsoft.DotNet.Cli.Utils { - internal static class CommandResolver + internal class CommandResolver { public static CommandSpec TryResolveCommandSpec( string commandName, @@ -14,6 +14,25 @@ namespace Microsoft.DotNet.Cli.Utils string configuration = Constants.DefaultConfiguration, string outputPath = null, string applicationName = null) + { + return TryResolveCommandSpec( + new DefaultCommandResolverPolicy(), + commandName, + args, + framework, + configuration, + outputPath, + applicationName); + } + + public static CommandSpec TryResolveCommandSpec( + ICommandResolverPolicy commandResolverPolicy, + string commandName, + IEnumerable args, + NuGetFramework framework = null, + string configuration = Constants.DefaultConfiguration, + string outputPath = null, + string applicationName = null) { var commandResolverArgs = new CommandResolverArguments { @@ -26,7 +45,7 @@ namespace Microsoft.DotNet.Cli.Utils ApplicationName = applicationName }; - var defaultCommandResolver = DefaultCommandResolverPolicy.Create(); + var defaultCommandResolver = commandResolverPolicy.CreateCommandResolver(); return defaultCommandResolver.Resolve(commandResolverArgs); } diff --git a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/DependencyContextBuilder.cs b/src/dotnet/CommandResolution/DepsJsonBuilder.cs similarity index 99% rename from src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/DependencyContextBuilder.cs rename to src/dotnet/CommandResolution/DepsJsonBuilder.cs index c6ee4223c..89cfea873 100644 --- a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/DependencyContextBuilder.cs +++ b/src/dotnet/CommandResolution/DepsJsonBuilder.cs @@ -12,13 +12,13 @@ using NuGet.Packaging; using NuGet.Packaging.Core; using NuGet.ProjectModel; -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.CommandResolution { - internal class DependencyContextBuilder + internal class DepsJsonBuilder { private readonly VersionFolderPathResolver _versionFolderPathResolver; - public DependencyContextBuilder() + public DepsJsonBuilder() { // This resolver is only used for building file names, so that base path is not required. _versionFolderPathResolver = new VersionFolderPathResolver(path: null); diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/LockFilePathCalculator.cs b/src/dotnet/CommandResolution/LockFilePathCalculator.cs similarity index 62% rename from src/Microsoft.DotNet.Cli.Utils/CommandResolution/LockFilePathCalculator.cs rename to src/dotnet/CommandResolution/LockFilePathCalculator.cs index 044a49266..c4181ce34 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/LockFilePathCalculator.cs +++ b/src/dotnet/CommandResolution/LockFilePathCalculator.cs @@ -2,11 +2,13 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections.Generic; using System.IO; -using Microsoft.Build.Execution; +using System.Linq; +using Microsoft.Build.Evaluation; using NuGet.ProjectModel; -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.CommandResolution { internal class LockFilePathCalculator { @@ -19,12 +21,21 @@ namespace Microsoft.DotNet.Cli.Utils private string ResolveLockFilePathUsingCSProj(string projectDirectory) { string csProjPath = GetCSProjPath(projectDirectory); - if(csProjPath != null) + if(csProjPath == null) { - ProjectInstance projectInstance = new ProjectInstance(csProjPath, null, null); + return null; } - return null; + var globalProperties = new Dictionary() + { + { "MSBuildExtensionsPath", AppContext.BaseDirectory } + }; + + Project project = new Project(csProjPath, globalProperties, null); + // TODO: This is temporary. We should use ProjectLockFile property, but for some reason, it is coming up as project.lock.json + // instead of the path to project.assets.json. + var lockFilePath = project.AllEvaluatedProperties.FirstOrDefault(p => p.Name.Equals("BaseIntermediateOutputPath")).EvaluatedValue; + return Path.Combine(lockFilePath, "project.assets.json"); } private string ReturnProjectLockJson(string projectDirectory) diff --git a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/LockFileTargetExtensions.cs b/src/dotnet/CommandResolution/LockFileTargetExtensions.cs similarity index 98% rename from src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/LockFileTargetExtensions.cs rename to src/dotnet/CommandResolution/LockFileTargetExtensions.cs index 52c4d2aed..7ab64c627 100644 --- a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/LockFileTargetExtensions.cs +++ b/src/dotnet/CommandResolution/LockFileTargetExtensions.cs @@ -7,7 +7,7 @@ using System.Linq; using NuGet.Packaging.Core; using NuGet.ProjectModel; -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.CommandResolution { internal static class LockFileTargetExtensions { diff --git a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/NuGetUtils.cs b/src/dotnet/CommandResolution/NuGetUtils.cs similarity index 93% rename from src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/NuGetUtils.cs rename to src/dotnet/CommandResolution/NuGetUtils.cs index 2c569a8ab..6e5821451 100644 --- a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/NuGetUtils.cs +++ b/src/dotnet/CommandResolution/NuGetUtils.cs @@ -8,7 +8,7 @@ using System.Linq; using NuGet.Packaging.Core; using NuGet.ProjectModel; -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.CommandResolution { internal static class NuGetUtils { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs b/src/dotnet/CommandResolution/ProjectToolsCommandResolver.cs similarity index 96% rename from src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs rename to src/dotnet/CommandResolution/ProjectToolsCommandResolver.cs index 831ec04e9..76872e0e3 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs +++ b/src/dotnet/CommandResolution/ProjectToolsCommandResolver.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Common; @@ -11,7 +12,7 @@ using NuGet.ProjectModel; using NuGet.Versioning; using FileFormatException = Microsoft.DotNet.ProjectModel.FileFormatException; -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.CommandResolution { public class ProjectToolsCommandResolver : ICommandResolver { @@ -52,7 +53,8 @@ namespace Microsoft.DotNet.Cli.Utils IEnumerable args, string projectDirectory) { - var lockFile = new LockFileFormat().Read(Path.Combine(projectDirectory, LockFileFormat.LockFileName)); + var lockFilePathCalculator = new LockFilePathCalculator(); + var lockFile = new LockFileFormat().Read(lockFilePathCalculator.GetLockFilePath(projectDirectory)); var tools = lockFile.Tools.Where(t => t.Name.Contains(".NETCoreApp")).SelectMany(t => t.Libraries); return ResolveCommandSpecFromAllToolLibraries( @@ -209,7 +211,7 @@ namespace Microsoft.DotNet.Cli.Utils toolLibrary.Version.ToFullString(), Enumerable.Empty()); - var dependencyContext = new DependencyContextBuilder() + var dependencyContext = new DepsJsonBuilder() .Build(singleProjectInfo, null, toolLockFile, s_toolPackageFramework, null); var tempDepsFile = Path.GetTempFileName(); diff --git a/src/dotnet/CommandResolution/ProjectToolsCommandResolverPolicy.cs b/src/dotnet/CommandResolution/ProjectToolsCommandResolverPolicy.cs new file mode 100644 index 000000000..12b2f44f9 --- /dev/null +++ b/src/dotnet/CommandResolution/ProjectToolsCommandResolverPolicy.cs @@ -0,0 +1,18 @@ +using Microsoft.DotNet.Cli.Utils; + +namespace Microsoft.DotNet.Cli.CommandResolution +{ + public class ProjectToolsCommandResolverPolicy : ICommandResolverPolicy + { + public CompositeCommandResolver CreateCommandResolver() + { + var defaultCommandResolverPolicy = new DefaultCommandResolverPolicy(); + var compositeCommandResolver = defaultCommandResolverPolicy.CreateCommandResolver(); + var packagedCommandSpecFactory = new PackagedCommandSpecFactory(); + + compositeCommandResolver.AddCommandResolver(new ProjectToolsCommandResolver(packagedCommandSpecFactory)); + + return compositeCommandResolver; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/ResourceAssemblyInfo.cs b/src/dotnet/CommandResolution/ResourceAssemblyInfo.cs similarity index 90% rename from src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/ResourceAssemblyInfo.cs rename to src/dotnet/CommandResolution/ResourceAssemblyInfo.cs index 80346aae2..c69b0a037 100644 --- a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/ResourceAssemblyInfo.cs +++ b/src/dotnet/CommandResolution/ResourceAssemblyInfo.cs @@ -1,7 +1,7 @@ // 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. -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.CommandResolution { internal class ResourceAssemblyInfo { diff --git a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/SingleProjectInfo.cs b/src/dotnet/CommandResolution/SingleProjectInfo.cs similarity index 93% rename from src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/SingleProjectInfo.cs rename to src/dotnet/CommandResolution/SingleProjectInfo.cs index fa15442d6..917680abb 100644 --- a/src/Microsoft.DotNet.Cli.Utils/DependencyContextBuilding/SingleProjectInfo.cs +++ b/src/dotnet/CommandResolution/SingleProjectInfo.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.CommandResolution { internal class SingleProjectInfo { diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index e85abf5cf..f04cfbc01 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using Microsoft.DotNet.Cli.CommandResolution; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Configurer; using Microsoft.DotNet.PlatformAbstractions; @@ -188,7 +189,12 @@ namespace Microsoft.DotNet.Cli } else { - CommandResult result = Command.Create("dotnet-" + command, appArgs, FrameworkConstants.CommonFrameworks.NetStandardApp15) + var projectToolsCommandResolver = new ProjectToolsCommandResolverPolicy(); + CommandResult result = Command.Create( + projectToolsCommandResolver, + "dotnet-" + command, + appArgs, + FrameworkConstants.CommonFrameworks.NetStandardApp15) .Execute(); exitCode = result.ExitCode; } diff --git a/test/EndToEnd/GivenDotNetUsesMSBuild.cs b/test/EndToEnd/GivenDotNetUsesMSBuild.cs index 063944301..db5b2b73a 100644 --- a/test/EndToEnd/GivenDotNetUsesMSBuild.cs +++ b/test/EndToEnd/GivenDotNetUsesMSBuild.cs @@ -43,5 +43,27 @@ namespace Microsoft.DotNet.Tests.EndToEnd .HaveStdOutContaining("Hello World!"); } } + + [Fact] + public void ItCanRunToolsInACSProj() + { + var testAppName = "MSBuildTestApp"; + var testInstance = TestAssetsManager + .CreateTestInstance(testAppName); + + var testProjectDirectory = testInstance.TestRoot; + + new Restore3Command() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should() + .Pass(); + + new DotnetCommand() + .WithWorkingDirectory(testInstance.TestRoot) + .ExecuteWithCapturedOutput("portable") + .Should() + .Pass(); + } } } diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs index b2e354e30..2a09e9d47 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs @@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var resolvers = defaultCommandResolver.OrderedCommandResolvers; - resolvers.Should().HaveCount(7); + resolvers.Should().HaveCount(6); resolvers.Select(r => r.GetType()) .Should() @@ -25,7 +25,6 @@ namespace Microsoft.DotNet.Cli.Utils.Tests new []{ typeof(MuxerCommandResolver), typeof(RootedCommandResolver), - typeof(ProjectToolsCommandResolver), typeof(AppBaseDllCommandResolver), typeof(AppBaseCommandResolver), typeof(PathCommandResolver), diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/project.json b/test/Microsoft.DotNet.Cli.Utils.Tests/project.json index febb3f9f2..5d3016b5f 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/project.json +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/project.json @@ -20,10 +20,10 @@ }, "System.Diagnostics.TraceSource": "4.0.0", "System.Runtime.Serialization.Primitives": "4.1.1", - "NuGet.Versioning": "3.6.0-beta.1.msbuild.15", - "NuGet.Packaging": "3.6.0-beta.1.msbuild.15", - "NuGet.Frameworks": "3.6.0-beta.1.msbuild.15", - "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15", + "NuGet.Versioning": "3.6.0-beta.1.msbuild.17", + "NuGet.Packaging": "3.6.0-beta.1.msbuild.17", + "NuGet.Frameworks": "3.6.0-beta.1.msbuild.17", + "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.17", "Microsoft.DotNet.ProjectModel": { "target": "project" }, diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/project.json b/test/Microsoft.DotNet.ProjectModel.Tests/project.json index fc6e86a8f..b8492a1bf 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/project.json +++ b/test/Microsoft.DotNet.ProjectModel.Tests/project.json @@ -22,7 +22,7 @@ }, "xunit": "2.2.0-beta3-build3330", "dotnet-test-xunit": "1.0.0-rc2-350904-49", - "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15" + "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.17" }, "frameworks": { "netcoreapp1.0": { diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs b/test/dotnet.Tests/GivenAProjectToolsCommandResolver.cs similarity index 98% rename from test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs rename to test/dotnet.Tests/GivenAProjectToolsCommandResolver.cs index 7ce9874e4..3a023237f 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs +++ b/test/dotnet.Tests/GivenAProjectToolsCommandResolver.cs @@ -4,6 +4,8 @@ using System.IO; using System.Linq; using FluentAssertions; +using Microsoft.DotNet.Cli.CommandResolution; +using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; @@ -12,7 +14,7 @@ using NuGet.ProjectModel; using NuGet.Versioning; using Xunit; -namespace Microsoft.DotNet.Cli.Utils.Tests +namespace Microsoft.DotNet.Tests { public class GivenAProjectToolsCommandResolver : TestBase { diff --git a/test/dotnet.Tests/GivenAProjectToolsCommandResolverPolicy.cs b/test/dotnet.Tests/GivenAProjectToolsCommandResolverPolicy.cs new file mode 100644 index 000000000..915be7f2f --- /dev/null +++ b/test/dotnet.Tests/GivenAProjectToolsCommandResolverPolicy.cs @@ -0,0 +1,39 @@ +// 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.Linq; +using FluentAssertions; +using Microsoft.DotNet.Cli.CommandResolution; +using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; + +namespace Microsoft.DotNet.Tests +{ + public class GivenAProjectToolsCommandResolverPolicy + { + [Fact] + public void It_contains_resolvers_in_the_right_order() + { + var projectToolsCommandResolverPolicy = new ProjectToolsCommandResolverPolicy(); + var defaultCommandResolver = projectToolsCommandResolverPolicy.CreateCommandResolver(); + + var resolvers = defaultCommandResolver.OrderedCommandResolvers; + + resolvers.Should().HaveCount(7); + + resolvers.Select(r => r.GetType()) + .Should() + .ContainInOrder( + new []{ + typeof(MuxerCommandResolver), + typeof(RootedCommandResolver), + typeof(AppBaseDllCommandResolver), + typeof(AppBaseCommandResolver), + typeof(PathCommandResolver), + typeof(PublishedPathCommandResolver), + typeof(ProjectToolsCommandResolver) + }); + } + } +} diff --git a/test/dotnet.Tests/GivenThatDotNetRunsCommands.cs b/test/dotnet.Tests/GivenThatDotNetRunsCommands.cs index b944c302e..e2eb4631d 100644 --- a/test/dotnet.Tests/GivenThatDotNetRunsCommands.cs +++ b/test/dotnet.Tests/GivenThatDotNetRunsCommands.cs @@ -26,6 +26,7 @@ namespace Microsoft.DotNet.Tests .HaveFile("project.lock.json"); new DotnetCommand() + .WithWorkingDirectory(testInstance.TestRoot) .ExecuteWithCapturedOutput("crash") .Should() .Fail()