From 64508f08abd8909cf2bb155b3bc4dcdf5c4824e9 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Thu, 2 Jun 2016 10:50:38 -0700 Subject: [PATCH] fixes #2408 stop using corehost to activate projectdependencycommands --- .../dotnet-cli-build/PrepareTargets.cs | 1 - .../PackagedCommandSpecFactory.cs | 53 +++++-------------- .../GivenAProjectDependencyCommandResolver.cs | 6 +-- 3 files changed, 15 insertions(+), 45 deletions(-) diff --git a/build_projects/dotnet-cli-build/PrepareTargets.cs b/build_projects/dotnet-cli-build/PrepareTargets.cs index b35465f36..b31827060 100644 --- a/build_projects/dotnet-cli-build/PrepareTargets.cs +++ b/build_projects/dotnet-cli-build/PrepareTargets.cs @@ -232,7 +232,6 @@ namespace Microsoft.DotNet.Cli.Build sharedHostInstallerDownloadFile).Wait(); File.Copy(sharedHostInstallerDownloadFile, sharedHostInstallerDestinationFile, true); - } return c.Success(); diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs index 106049425..6842d3e13 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs @@ -36,15 +36,12 @@ namespace Microsoft.DotNet.Cli.Utils return null; } - var isPortable = IsPortableApp(commandPath, runtimeConfigPath); - - return CreateCommandSpecWrappingWithCorehostIfDll( + return CreateCommandSpecWrappingWithMuxerIfDll( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, nugetPackagesRoot, - isPortable, runtimeConfigPath); } @@ -58,65 +55,57 @@ namespace Microsoft.DotNet.Cli.Utils return filePath; } - private CommandSpec CreateCommandSpecWrappingWithCorehostIfDll( + private CommandSpec CreateCommandSpecWrappingWithMuxerIfDll( string commandPath, IEnumerable commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy, string nugetPackagesRoot, - bool isPortable, string runtimeConfigPath) { var commandExtension = Path.GetExtension(commandPath); if (commandExtension == FileNameSuffixes.DotNet.DynamicLib) { - return CreatePackageCommandSpecUsingCorehost( + return CreatePackageCommandSpecUsingMuxer( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, nugetPackagesRoot, - isPortable, runtimeConfigPath); } return CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy); } - private CommandSpec CreatePackageCommandSpecUsingCorehost( + private CommandSpec CreatePackageCommandSpecUsingMuxer( string commandPath, IEnumerable commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy, string nugetPackagesRoot, - bool isPortable, string runtimeConfigPath) { var host = string.Empty; var arguments = new List(); - if (isPortable) - { - var muxer = new Muxer(); + var muxer = new Muxer(); - host = muxer.MuxerPath; - if (host == null) - { - throw new Exception("Unable to locate dotnet multiplexer"); - } - - arguments.Add("exec"); - } - else + host = muxer.MuxerPath; + if (host == null) { - host = CoreHost.HostExePath; + throw new Exception("Unable to locate dotnet multiplexer"); } + + arguments.Add("exec"); + if (runtimeConfigPath != null) { arguments.Add("--runtimeconfig"); arguments.Add(runtimeConfigPath); } + if (depsFilePath != null) { arguments.Add("--depsfile"); @@ -141,23 +130,5 @@ namespace Microsoft.DotNet.Cli.Utils return new CommandSpec(commandPath, escapedArgs, commandResolutionStrategy); } - - private bool IsPortableApp(string commandPath, string runtimeConfigPath) - { - var commandDir = Path.GetDirectoryName(commandPath); - - runtimeConfigPath = string.IsNullOrEmpty(runtimeConfigPath) - ? Directory.EnumerateFiles(commandDir).FirstOrDefault(x => x.EndsWith("runtimeconfig.json")) - : runtimeConfigPath; - - if (runtimeConfigPath == null || !File.Exists(runtimeConfigPath)) - { - return false; - } - - var runtimeConfig = new RuntimeConfig(runtimeConfigPath); - - return runtimeConfig.IsPortable; - } } } diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependencyCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependencyCommandResolver.cs index 29a31653c..3f2d057fa 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependencyCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependencyCommandResolver.cs @@ -114,7 +114,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests } [Fact] - public void It_returns_a_CommandSpec_with_CoreHost_as_FileName_and_CommandName_in_Args_when_CommandName_exists_in_ProjectDependencies() + public void It_returns_a_CommandSpec_with_Dotnet_as_FileName_and_CommandName_in_Args_when_CommandName_exists_in_ProjectDependencies() { var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver(); @@ -133,7 +133,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandFile = Path.GetFileNameWithoutExtension(result.Path); - commandFile.Should().Be("corehost"); + commandFile.Should().Be("dotnet"); result.Args.Should().Contain(commandResolverArguments.CommandName); } @@ -159,7 +159,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests } [Fact] - public void It_passes_depsfile_arg_to_corehost_when_returning_a_commandspec() + public void It_passes_depsfile_arg_to_host_when_returning_a_commandspec() { var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();