private CommandSpec CreateCommandSpecWrappedWithCmd( string command, IEnumerable <string> args, CommandResolutionStrategy resolutionStrategy) { var comSpec = Environment.GetEnvironmentVariable("ComSpec") ?? "cmd.exe"; // Handle the case where ComSpec is already the command if (command.Equals(comSpec, StringComparison.OrdinalIgnoreCase)) { command = args.FirstOrDefault(); args = args.Skip(1); } var cmdEscapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForCmdProcessStart(args); if (ArgumentEscaper.ShouldSurroundWithQuotes(command)) { command = $"\"{command}\""; } var escapedArgString = $"/s /c \"{command} {cmdEscapedArgs}\""; return(new CommandSpec(comSpec, escapedArgString, resolutionStrategy)); }
private static string ResolveExecutableFromPath(string executable, ref string args, ref CommandResolutionStrategy resolutionStrategy) { resolutionStrategy = CommandResolutionStrategy.Path; foreach (string suffix in Constants.RunnableSuffixes) { var fullExecutable = Path.GetFullPath(Path.Combine( AppContext.BaseDirectory, executable + suffix)); if (File.Exists(fullExecutable)) { executable = fullExecutable; resolutionStrategy = CommandResolutionStrategy.BaseDirectory; // In priority order we've found the best runnable extension, so break. break; } } // On Windows, we want to avoid using "cmd" if possible (it mangles the colors, and a bunch of other things) // So, do a quick path search to see if we can just directly invoke it var useCmd = ShouldUseCmd(executable); if (useCmd) { var comSpec = Environment.GetEnvironmentVariable("ComSpec"); // wrap 'executable' within quotes to deal woth space in its path. args = $"/S /C \"\"{executable}\" {args}\""; executable = comSpec; } return executable; }
private CommandSpec CreatePackageCommandSpecUsingMuxer( string commandPath, IEnumerable <string> commandArguments, CommandResolutionStrategy commandResolutionStrategy) { var arguments = new List <string>(); var muxer = new Muxer(); var host = muxer.MuxerPath; if (host == null) { throw new Exception(LocalizableStrings.UnableToLocateDotnetMultiplexer); } arguments.Add(commandPath); if (commandArguments != null) { arguments.AddRange(commandArguments); } return(CreateCommandSpec(host, arguments, commandResolutionStrategy)); }
private CommandSpec CreateCommandSpecWrappingWithCorehostIfDll( string commandPath, IEnumerable <string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy, string nugetPackagesRoot, bool isPortable, string runtimeConfigPath) { var commandExtension = Path.GetExtension(commandPath); if (commandExtension == FileNameSuffixes.DotNet.DynamicLib) { return(CreatePackageCommandSpecUsingCorehost( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, nugetPackagesRoot, isPortable, runtimeConfigPath)); } return(CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy)); }
private static CommandSpec CreateComSpecCommandSpec( string command, IEnumerable <string> args, CommandResolutionStrategy resolutionStrategy) { // To prevent Command Not Found, comspec gets passed in as // the command already in some cases var comSpec = Environment.GetEnvironmentVariable("ComSpec"); if (command.Equals(comSpec, StringComparison.OrdinalIgnoreCase)) { command = args.FirstOrDefault(); args = args.Skip(1); } var cmdEscapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForCmdProcessStart(args); if (ArgumentEscaper.ShouldSurroundWithQuotes(command)) { command = $"\"{command}\""; } var escapedArgString = $"/s /c \"{command} {cmdEscapedArgs}\""; return(new CommandSpec(comSpec, escapedArgString, resolutionStrategy)); }
public CommandSpec CreateCommandSpecFromLibrary( LockFileTargetLibrary toolLibrary, string commandName, IEnumerable<string> commandArguments, IEnumerable<string> allowedExtensions, string nugetPackagesRoot, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath, string runtimeConfigPath) { var toolAssembly = toolLibrary?.RuntimeAssemblies .FirstOrDefault(r => Path.GetFileNameWithoutExtension(r.Path) == commandName); if (toolAssembly == null) { return null; } var commandPath = GetCommandFilePath(nugetPackagesRoot, toolLibrary, toolAssembly); if (!File.Exists(commandPath)) { return null; } return CreateCommandSpecWrappingWithMuxerIfDll( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, nugetPackagesRoot, runtimeConfigPath); }
public CommandSpec CreateCommandSpecFromLibrary( LockFilePackageLibrary library, string commandName, IEnumerable <string> commandArguments, IEnumerable <string> allowedExtensions, string nugetPackagesRoot, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath) { var packageDirectory = GetPackageDirectoryFullPath(library, nugetPackagesRoot); if (!Directory.Exists(packageDirectory)) { return(null); } var commandFile = GetCommandFileRelativePath(library, commandName, allowedExtensions); if (commandFile == null) { return(null); } var commandPath = Path.Combine(packageDirectory, commandFile); return(CreateCommandSpecWrappingWithCorehostfDll( commandPath, commandArguments, depsFilePath, commandResolutionStrategy)); }
private static CommandSpec CreateCommandSpecPreferringExe( string commandName, IEnumerable <string> args, string commandPath, CommandResolutionStrategy resolutionStrategy, bool useComSpec = false) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Path.GetExtension(commandPath).Equals(".cmd", StringComparison.OrdinalIgnoreCase)) { var preferredCommandPath = Env.GetCommandPath(commandName, ".exe"); // Use cmd if we can't find an exe if (preferredCommandPath == null) { useComSpec = true; } else { commandPath = preferredCommandPath; } } if (useComSpec) { return(CreateComSpecCommandSpec(commandPath, args, resolutionStrategy)); } else { var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args); return(new CommandSpec(commandPath, escapedArgs, resolutionStrategy)); } }
public CommandSpec CreateCommandSpec( string commandName, IEnumerable <string> args, string commandPath, CommandResolutionStrategy resolutionStrategy, IEnvironmentProvider environment) { var useCmdWrapper = false; if (Path.GetExtension(commandPath).Equals(".cmd", StringComparison.OrdinalIgnoreCase)) { var preferredCommandPath = environment.GetCommandPath(commandName, ".exe"); if (preferredCommandPath == null) { useCmdWrapper = true; } else { commandPath = preferredCommandPath; } } return(useCmdWrapper ? CreateCommandSpecWrappedWithCmd(commandPath, args, resolutionStrategy) : CreateCommandSpecFromExecutable(commandPath, args, resolutionStrategy)); }
public CommandSpec CreateCommandSpecFromLibrary( LockFileTargetLibrary toolLibrary, string commandName, IEnumerable<string> commandArguments, IEnumerable<string> allowedExtensions, string nugetPackagesRoot, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath) { var toolAssembly = toolLibrary?.RuntimeAssemblies .FirstOrDefault(r => Path.GetFileNameWithoutExtension(r.Path) == commandName); if (toolAssembly == null) { return null; } var commandPath = GetCommandFilePath(nugetPackagesRoot, toolLibrary, toolAssembly); if (!File.Exists(commandPath)) { return null; } var isPortable = IsPortableApp(commandPath); return CreateCommandSpecWrappingWithCorehostIfDll( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, nugetPackagesRoot, isPortable); }
private CommandSpec CreateCommandSpecWrappedWithCmd( string command, IEnumerable<string> args, CommandResolutionStrategy resolutionStrategy) { var comSpec = Environment.GetEnvironmentVariable("ComSpec") ?? "cmd.exe"; // Handle the case where ComSpec is already the command if (command.Equals(comSpec, StringComparison.OrdinalIgnoreCase)) { command = args.FirstOrDefault(); args = args.Skip(1); } var cmdEscapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForCmdProcessStart(args); if (ArgumentEscaper.ShouldSurroundWithQuotes(command)) { command = $"\"{command}\""; } var escapedArgString = $"/s /c \"{command} {cmdEscapedArgs}\""; return new CommandSpec(comSpec, escapedArgString, resolutionStrategy); }
public CommandSpec CreateCommandSpec( string commandName, IEnumerable<string> args, string commandPath, CommandResolutionStrategy resolutionStrategy, IEnvironmentProvider environment) { var useCmdWrapper = false; if (Path.GetExtension(commandPath).Equals(".cmd", StringComparison.OrdinalIgnoreCase)) { var preferredCommandPath = environment.GetCommandPath(commandName, ".exe"); if (preferredCommandPath == null) { useCmdWrapper = true; } else { commandPath = preferredCommandPath; } } return useCmdWrapper ? CreateCommandSpecWrappedWithCmd(commandPath, args, resolutionStrategy) : CreateCommandSpecFromExecutable(commandPath, args, resolutionStrategy); }
public CommandSpec CreateCommandSpecFromLibrary( LockFilePackageLibrary library, string commandName, IEnumerable<string> commandArguments, IEnumerable<string> allowedExtensions, string nugetPackagesRoot, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath) { var packageDirectory = GetPackageDirectoryFullPath(library, nugetPackagesRoot); if (!Directory.Exists(packageDirectory)) { return null; } var commandFile = GetCommandFileRelativePath(library, commandName, allowedExtensions); if (commandFile == null) { return null; } var commandPath = Path.Combine(packageDirectory, commandFile); return CreateCommandSpecWrappingWithCorehostfDll( commandPath, commandArguments, depsFilePath, commandResolutionStrategy); }
private CommandSpec CreateCommandSpecFromExecutable( string command, IEnumerable<string> args, CommandResolutionStrategy resolutionStrategy) { var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args); return new CommandSpec(command, escapedArgs, resolutionStrategy); }
private CommandSpec CreateCommandSpecFromExecutable( string command, IEnumerable <string> args, CommandResolutionStrategy resolutionStrategy) { var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args); return(new CommandSpec(command, escapedArgs, resolutionStrategy)); }
private CommandSpec CreateCommandSpec( string commandPath, IEnumerable <string> commandArguments, CommandResolutionStrategy commandResolutionStrategy) { var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(commandArguments); return(new CommandSpec(commandPath, escapedArgs, commandResolutionStrategy)); }
public CommandSpec CreateCommandSpec( string commandName, IEnumerable<string> args, string commandPath, CommandResolutionStrategy resolutionStrategy, IEnvironmentProvider environment) { var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args); return new CommandSpec(commandPath, escapedArgs, resolutionStrategy); }
public CommandSpec( string path, string args, CommandResolutionStrategy resolutionStrategy, Dictionary <string, string> environmentVariables = null) { Path = path; Args = args; ResolutionStrategy = resolutionStrategy; EnvironmentVariables = environmentVariables ?? new Dictionary <string, string>(); }
public CommandSpec CreateCommandSpec( string commandName, IEnumerable <string> args, string commandPath, CommandResolutionStrategy resolutionStrategy, IEnvironmentProvider environment) { var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args); return(new CommandSpec(commandPath, escapedArgs, resolutionStrategy)); }
public CommandSpec CreateCommandSpecFromPublishFolder( string commandPath, IEnumerable <string> commandArguments, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath, string runtimeConfigPath) { return(CreateCommandSpecWrappingWithMuxerIfDll( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, runtimeConfigPath)); }
private CommandSpec CreatePackageCommandSpecUsingMuxer( string commandPath, IEnumerable <string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy, IEnumerable <string> packageFolders, string runtimeConfigPath) { var host = string.Empty; var arguments = new List <string>(); var muxer = new Muxer(); host = muxer.MuxerPath; if (host == null) { throw new Exception(LocalizableStrings.UnableToLocateDotnetMultiplexer); } arguments.Add("exec"); if (runtimeConfigPath != null) { arguments.Add("--runtimeconfig"); arguments.Add(runtimeConfigPath); } if (depsFilePath != null) { arguments.Add("--depsfile"); arguments.Add(depsFilePath); } foreach (var packageFolder in packageFolders) { arguments.Add("--additionalprobingpath"); arguments.Add(packageFolder); } if (_addAdditionalArguments != null) { _addAdditionalArguments(commandPath, arguments); } arguments.Add(commandPath); arguments.AddRange(commandArguments); return(CreateCommandSpec(host, arguments, commandResolutionStrategy)); }
public CommandSpec CreateCommandSpecFromLibrary( LockFileTargetLibrary toolLibrary, string commandName, IEnumerable <string> commandArguments, IEnumerable <string> allowedExtensions, LockFile lockFile, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath, string runtimeConfigPath) { Reporter.Verbose.WriteLine(string.Format( LocalizableStrings.AttemptingToFindCommand, PackagedCommandSpecFactoryName, commandName, toolLibrary.Name)); var toolAssembly = toolLibrary?.RuntimeAssemblies .FirstOrDefault(r => Path.GetFileNameWithoutExtension(r.Path) == commandName); if (toolAssembly == null) { Reporter.Verbose.WriteLine(string.Format( LocalizableStrings.FailedToFindToolAssembly, PackagedCommandSpecFactoryName, commandName)); return(null); } var commandPath = GetCommandFilePath(lockFile, toolLibrary, toolAssembly); if (!File.Exists(commandPath)) { Reporter.Verbose.WriteLine(string.Format( LocalizableStrings.FailedToFindCommandPath, PackagedCommandSpecFactoryName, commandPath)); return(null); } return(CreateCommandSpecWrappingWithMuxerIfDll( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, lockFile.GetNormalizedPackageFolders(), runtimeConfigPath)); }
private CommandSpec CreatePackageCommandSpecUsingCorehost( string commandPath, IEnumerable <string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy, string nugetPackagesRoot, bool isPortable, string runtimeConfigPath) { var host = string.Empty; var arguments = new List <string>(); if (isPortable) { var muxer = new Muxer(); host = muxer.MuxerPath; if (host == null) { throw new Exception("Unable to locate dotnet multiplexer"); } arguments.Add("exec"); } else { host = CoreHost.HostExePath; } if (runtimeConfigPath != null) { arguments.Add("--runtimeconfig"); arguments.Add(runtimeConfigPath); } if (depsFilePath != null) { arguments.Add("--depsfile"); arguments.Add(depsFilePath); } arguments.Add("--additionalprobingpath"); arguments.Add(nugetPackagesRoot); arguments.Add(commandPath); arguments.AddRange(commandArguments); return(CreateCommandSpec(host, arguments, commandResolutionStrategy)); }
private static CommandSpec CreateCommandSpecPreferringExe(string commandName, string args, string commandPath, CommandResolutionStrategy resolutionStrategy) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Path.GetExtension(commandPath).Equals(".cmd", StringComparison.OrdinalIgnoreCase)) { var preferredCommandPath = Env.GetCommandPath(commandName, ".exe"); if (preferredCommandPath != null) { commandPath = Environment.GetEnvironmentVariable("ComSpec"); args = $"/S /C \"\"{preferredCommandPath}\" {args}\""; } } return(new CommandSpec(commandPath, args, resolutionStrategy)); }
private CommandSpec CreateCommandSpecWrappingWithCorehostfDll( string commandPath, IEnumerable <string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy) { var commandExtension = Path.GetExtension(commandPath); if (commandExtension == FileNameSuffixes.DotNet.DynamicLib) { return(CreatePackageCommandSpecUsingCorehost( commandPath, commandArguments, depsFilePath, commandResolutionStrategy)); } return(CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy)); }
private CommandSpec CreateCommandSpecWrappingWithCorehostfDll( string commandPath, IEnumerable<string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy) { var commandExtension = Path.GetExtension(commandPath); if (commandExtension == FileNameSuffixes.DotNet.DynamicLib) { return CreatePackageCommandSpecUsingCorehost( commandPath, commandArguments, depsFilePath, commandResolutionStrategy); } return CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy); }
private CommandSpec CreatePackageCommandSpecUsingMuxer( string commandPath, IEnumerable<string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy, string nugetPackagesRoot, string runtimeConfigPath) { var host = string.Empty; var arguments = new List<string>(); var muxer = new Muxer(); host = muxer.MuxerPath; if (host == null) { 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"); arguments.Add(depsFilePath); } arguments.Add("--additionalprobingpath"); arguments.Add(nugetPackagesRoot); arguments.Add(commandPath); arguments.AddRange(commandArguments); return CreateCommandSpec(host, arguments, commandResolutionStrategy); }
private Command(string executable, string args, CommandResolutionStrategy resolutionStrategy) { // Set the things we need var psi = new ProcessStartInfo() { FileName = executable, Arguments = args, RedirectStandardError = true, RedirectStandardOutput = true }; _process = new Process() { StartInfo = psi }; _stdOut = new StreamForwarder(); _stdErr = new StreamForwarder(); ResolutionStrategy = resolutionStrategy; }
private CommandSpec CreatePackageCommandSpecUsingCorehost( string commandPath, IEnumerable <string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy) { var corehost = CoreHost.HostExePath; var arguments = new List <string>(); arguments.Add(commandPath); if (depsFilePath != null) { arguments.Add($"--depsfile:{depsFilePath}"); } arguments.AddRange(commandArguments); return(CreateCommandSpec(corehost, arguments, commandResolutionStrategy)); }
private Command(string executable, string args, CommandResolutionStrategy resolutionStrategy) { // Set the things we need var psi = new ProcessStartInfo() { FileName = executable, Arguments = args, RedirectStandardError = true, RedirectStandardOutput = true }; _process = new Process() { StartInfo = psi }; _stdOut = new StreamForwarder(); _stdErr = new StreamForwarder(); ResolutionStrategy = resolutionStrategy; }
public CommandSpec CreateCommandSpecFromLibrary( LockFileTargetLibrary toolLibrary, string commandName, IEnumerable <string> commandArguments, IEnumerable <string> allowedExtensions, string nugetPackagesRoot, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath, string runtimeConfigPath) { return(CreateCommandSpecFromLibrary( toolLibrary, commandName, commandArguments, allowedExtensions, new List <string> { nugetPackagesRoot }, commandResolutionStrategy, depsFilePath, runtimeConfigPath)); }
public CommandSpec CreateCommandSpecFromLibrary( LockFileTargetLibrary toolLibrary, string commandName, IEnumerable <string> commandArguments, IEnumerable <string> allowedExtensions, string nugetPackagesRoot, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath, string runtimeConfigPath) { Reporter.Verbose.WriteLine($"packagedcommandspecfactory: attempting to find command {commandName} in {toolLibrary.Name}"); var toolAssembly = toolLibrary?.RuntimeAssemblies .FirstOrDefault(r => Path.GetFileNameWithoutExtension(r.Path) == commandName); if (toolAssembly == null) { Reporter.Verbose.WriteLine($"packagedcommandspecfactory: failed to find toolAssembly for {commandName}"); return(null); } var commandPath = GetCommandFilePath(nugetPackagesRoot, toolLibrary, toolAssembly); if (!File.Exists(commandPath)) { Reporter.Verbose.WriteLine($"packagedcommandspecfactory: failed to find commandPath {commandPath}"); return(null); } return(CreateCommandSpecWrappingWithMuxerIfDll( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, nugetPackagesRoot, runtimeConfigPath)); }
private CommandSpec CreateCommandSpecUsingMuxerIfPortable( string commandPath, IEnumerable <string> commandArgs, string depsJsonFile, CommandResolutionStrategy commandResolutionStrategy, string nugetPackagesRoot, bool isPortable) { var depsFileArguments = GetDepsFileArguments(depsJsonFile); var additionalProbingPathArguments = GetAdditionalProbingPathArguments(); var muxerArgs = new List <string>(); muxerArgs.Add("exec"); muxerArgs.AddRange(depsFileArguments); muxerArgs.AddRange(additionalProbingPathArguments); muxerArgs.Add(commandPath); muxerArgs.AddRange(commandArgs); var escapedArgString = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(muxerArgs); return(new CommandSpec(_muxer.MuxerPath, escapedArgString, commandResolutionStrategy)); }
private CommandSpec CreateCommandSpecWrappingWithMuxerIfDll( string commandPath, IEnumerable<string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy, string nugetPackagesRoot, string runtimeConfigPath) { var commandExtension = Path.GetExtension(commandPath); if (commandExtension == FileNameSuffixes.DotNet.DynamicLib) { return CreatePackageCommandSpecUsingMuxer( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, nugetPackagesRoot, runtimeConfigPath); } return CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy); }
private CommandSpec CreateCommandSpecWrappingWithMuxerIfDll( string commandPath, IEnumerable <string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy, IEnumerable <string> packageFolders, string runtimeConfigPath) { var commandExtension = Path.GetExtension(commandPath); if (commandExtension == FileNameSuffixes.DotNet.DynamicLib) { return(CreatePackageCommandSpecUsingMuxer( commandPath, commandArguments, depsFilePath, commandResolutionStrategy, packageFolders, runtimeConfigPath)); } return(CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy)); }
private CommandSpec CreatePackageCommandSpecUsingMuxer( string commandPath, IEnumerable <string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy, string runtimeConfigPath) { var arguments = new List <string>(); var muxer = new Muxer(); var host = muxer.MuxerPath; if (host == null) { 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"); arguments.Add(depsFilePath); } arguments.Add(commandPath); arguments.AddRange(commandArguments); return(CreateCommandSpec(host, arguments, commandResolutionStrategy)); }
private static void ResolveExecutablePath(ref string executable, ref string args, ref CommandResolutionStrategy resolutionStrategy, NuGetFramework framework = null) { executable = ResolveExecutablePathFromProject(executable, framework, ref resolutionStrategy) ?? ResolveExecutableFromPath(executable, ref args, ref resolutionStrategy); }
private CommandSpec CreateCommandSpecUsingMuxerIfPortable( string commandPath, IEnumerable<string> commandArgs, string depsJsonFile, CommandResolutionStrategy commandResolutionStrategy, string nugetPackagesRoot, bool isPortable) { var depsFileArguments = GetDepsFileArguments(depsJsonFile); var additionalProbingPathArguments = GetAdditionalProbingPathArguments(); var muxerArgs = new List<string>(); muxerArgs.Add("exec"); muxerArgs.AddRange(depsFileArguments); muxerArgs.AddRange(additionalProbingPathArguments); muxerArgs.Add(commandPath); muxerArgs.AddRange(commandArgs); var escapedArgString = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(muxerArgs); return new CommandSpec(_muxer.MuxerPath, escapedArgString, commandResolutionStrategy); }
private static string ResolveExecutablePathFromProject(string executable, NuGetFramework framework, ref CommandResolutionStrategy resolutionStrategy) { if (framework == null) { return(null); } var projectRootPath = Directory.GetCurrentDirectory(); if (!File.Exists(Path.Combine(projectRootPath, Project.FileName))) { return(null); } var commandName = Path.GetFileNameWithoutExtension(executable); var projectContext = ProjectContext.Create(projectRootPath, framework); var commandPackage = projectContext.LibraryManager.GetLibraries() .Where(l => l.GetType() == typeof(PackageDescription)) .Select(l => l as PackageDescription) .FirstOrDefault(p => { var fileNames = p.Library.Files .Select(Path.GetFileName) .Where(n => Path.GetFileNameWithoutExtension(n) == commandName) .ToList(); return(fileNames.Contains(commandName + FileNameSuffixes.DotNet.Exe) && fileNames.Contains(commandName + FileNameSuffixes.DotNet.DynamicLib) && fileNames.Contains(commandName + FileNameSuffixes.Deps)); }); if (commandPackage == null) { return(null); } var commandPath = commandPackage.Library.Files .First(f => Path.GetFileName(f) == commandName + FileNameSuffixes.DotNet.Exe); resolutionStrategy = CommandResolutionStrategy.NugetPackage; return(Path.Combine(projectContext.PackagesDirectory, commandPackage.Path, commandPath)); }
private static CommandSpec CreateCommandSpecPreferringExe(string commandName, string args, string commandPath, CommandResolutionStrategy resolutionStrategy) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Path.GetExtension(commandPath).Equals(".cmd", StringComparison.OrdinalIgnoreCase)) { var preferredCommandPath = Env.GetCommandPath(commandName, ".exe"); if (preferredCommandPath != null) { commandPath = Environment.GetEnvironmentVariable("ComSpec"); args = $"/S /C \"\"{preferredCommandPath}\" {args}\""; } } return new CommandSpec(commandPath, args, resolutionStrategy); }
public CommandSpec(string path, string args, CommandResolutionStrategy resolutionStrategy) { Path = path; Args = args; ResolutionStrategy = resolutionStrategy; }
public CommandSpec(string path, string args, CommandResolutionStrategy resolutionStrategy) { Path = path; Args = args; ResolutionStrategy = resolutionStrategy; }
private static void ResolveExecutablePath(ref string executable, ref string args, ref CommandResolutionStrategy resolutionStrategy, NuGetFramework framework = null) { executable = ResolveExecutablePathFromProject(executable, framework, ref resolutionStrategy) ?? ResolveExecutableFromPath(executable, ref args, ref resolutionStrategy); }
private static CommandSpec CreateCommandSpecPreferringExe( string commandName, IEnumerable<string> args, string commandPath, CommandResolutionStrategy resolutionStrategy) { var useComSpec = false; if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows && Path.GetExtension(commandPath).Equals(".cmd", StringComparison.OrdinalIgnoreCase)) { var preferredCommandPath = Env.GetCommandPath(commandName, ".exe"); // Use cmd if we can't find an exe if (preferredCommandPath == null) { useComSpec = true; } else { commandPath = preferredCommandPath; } } if (useComSpec) { return CreateCmdCommandSpec(commandPath, args, resolutionStrategy); } else { var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args); return new CommandSpec(commandPath, escapedArgs, resolutionStrategy); } }
private static string ResolveExecutablePathFromProject(string executable, NuGetFramework framework, ref CommandResolutionStrategy resolutionStrategy) { if (framework == null) return null; var projectRootPath = Directory.GetCurrentDirectory(); if (!File.Exists(Path.Combine(projectRootPath, Project.FileName))) return null; var commandName = Path.GetFileNameWithoutExtension(executable); var projectContext = ProjectContext.Create(projectRootPath, framework); var commandPackage = projectContext.LibraryManager.GetLibraries() .Where(l => l.GetType() == typeof (PackageDescription)) .Select(l => l as PackageDescription) .FirstOrDefault(p => { var fileNames = p.Library.Files .Select(Path.GetFileName) .Where(n => Path.GetFileNameWithoutExtension(n) == commandName) .ToList(); return fileNames.Contains(commandName + FileNameSuffixes.DotNet.Exe) && fileNames.Contains(commandName + FileNameSuffixes.DotNet.DynamicLib) && fileNames.Contains(commandName + FileNameSuffixes.Deps); }); if (commandPackage == null) return null; var commandPath = commandPackage.Library.Files .First(f => Path.GetFileName(f) == commandName + FileNameSuffixes.DotNet.Exe); resolutionStrategy = CommandResolutionStrategy.NugetPackage; return Path.Combine(projectContext.PackagesDirectory, commandPackage.Path, commandPath); }
private static string ResolveExecutableFromPath(string executable, ref string args, ref CommandResolutionStrategy resolutionStrategy) { resolutionStrategy = CommandResolutionStrategy.Path; foreach (string suffix in Constants.RunnableSuffixes) { var fullExecutable = Path.GetFullPath(Path.Combine( AppContext.BaseDirectory, executable + suffix)); if (File.Exists(fullExecutable)) { executable = fullExecutable; resolutionStrategy = CommandResolutionStrategy.BaseDirectory; // In priority order we've found the best runnable extension, so break. break; } } // On Windows, we want to avoid using "cmd" if possible (it mangles the colors, and a bunch of other things) // So, do a quick path search to see if we can just directly invoke it var useCmd = ShouldUseCmd(executable); if (useCmd) { var comSpec = Environment.GetEnvironmentVariable("ComSpec"); // wrap 'executable' within quotes to deal woth space in its path. args = $"/S /C \"\"{executable}\" {args}\""; executable = comSpec; } return(executable); }
private CommandSpec CreatePackageCommandSpecUsingCorehost( string commandPath, IEnumerable<string> commandArguments, string depsFilePath, CommandResolutionStrategy commandResolutionStrategy) { var corehost = CoreHost.HostExePath; var arguments = new List<string>(); arguments.Add(commandPath); if (depsFilePath != null) { arguments.Add($"--depsfile:{depsFilePath}"); } arguments.AddRange(commandArguments); return CreateCommandSpec(corehost, arguments, commandResolutionStrategy); }
private CommandSpec CreateCommandSpec( string commandPath, IEnumerable<string> commandArguments, CommandResolutionStrategy commandResolutionStrategy) { var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(commandArguments); return new CommandSpec(commandPath, escapedArgs, commandResolutionStrategy); }
private static CommandSpec CreateComSpecCommandSpec( string command, IEnumerable<string> args, CommandResolutionStrategy resolutionStrategy) { // To prevent Command Not Found, comspec gets passed in as // the command already in some cases var comSpec = Environment.GetEnvironmentVariable("ComSpec"); if (command.Equals(comSpec, StringComparison.OrdinalIgnoreCase)) { command = args.FirstOrDefault(); args = args.Skip(1); } var cmdEscapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForCmdProcessStart(args); if (ArgumentEscaper.ShouldSurroundWithQuotes(command)) { command = $"\"{command}\""; } var escapedArgString = $"/s /c \"{command} {cmdEscapedArgs}\""; return new CommandSpec(comSpec, escapedArgString, resolutionStrategy); }