Enable resolving command paths from AppBase
This commit is contained in:
parent
bedeaaf2dc
commit
8274f5285b
2 changed files with 43 additions and 14 deletions
|
@ -17,6 +17,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
return ResolveFromRootedCommand(commandName, args) ??
|
return ResolveFromRootedCommand(commandName, args) ??
|
||||||
ResolveFromProjectDependencies(commandName, args, framework) ??
|
ResolveFromProjectDependencies(commandName, args, framework) ??
|
||||||
ResolveFromProjectTools(commandName, args) ??
|
ResolveFromProjectTools(commandName, args) ??
|
||||||
|
ResolveFromAppBase(commandName, args) ??
|
||||||
ResolveFromPath(commandName, args);
|
ResolveFromPath(commandName, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,22 +25,18 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
{
|
{
|
||||||
var commandPath = Env.GetCommandPath(commandName);
|
var commandPath = Env.GetCommandPath(commandName);
|
||||||
|
|
||||||
if (commandPath == null) return null;
|
return commandPath == null
|
||||||
|
? null
|
||||||
|
: CreateCommandSpecPreferringExe(commandName, args, commandPath, CommandResolutionStrategy.Path);
|
||||||
|
}
|
||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
|
private static CommandSpec ResolveFromAppBase(string commandName, string args)
|
||||||
Path.GetExtension(commandPath).Equals(".cmd", StringComparison.OrdinalIgnoreCase))
|
{
|
||||||
{
|
var commandPath = Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, commandName);
|
||||||
var preferredCommandPath = Env.GetCommandPath(commandName, ".exe");
|
|
||||||
|
|
||||||
if (preferredCommandPath != null)
|
return commandPath == null
|
||||||
{
|
? null
|
||||||
commandPath = Environment.GetEnvironmentVariable("ComSpec");
|
: CreateCommandSpecPreferringExe(commandName, args, commandPath, CommandResolutionStrategy.BaseDirectory);
|
||||||
|
|
||||||
args = $"/S /C \"\"{preferredCommandPath}\" {args}\"";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CommandSpec(commandPath, args, CommandResolutionStrategy.Path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CommandSpec ResolveFromRootedCommand(string commandName, string args)
|
private static CommandSpec ResolveFromRootedCommand(string commandName, string args)
|
||||||
|
@ -194,5 +191,24 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
return Path.Combine(context.GetOutputDirectoryPath(buildConfiguration),
|
return Path.Combine(context.GetOutputDirectoryPath(buildConfiguration),
|
||||||
context.ProjectFile.Name + FileNameSuffixes.Deps);
|
context.ProjectFile.Name + FileNameSuffixes.Deps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,5 +59,18 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
|
|
||||||
return commandPath;
|
return commandPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetCommandPathFromAppBase(string appBase, string commandName, params string[] extensions)
|
||||||
|
{
|
||||||
|
if (!extensions.Any())
|
||||||
|
{
|
||||||
|
extensions = Env.ExecutableExtensions.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
var commandPath = extensions.Select(e => Path.Combine(appBase, commandName + e))
|
||||||
|
.FirstOrDefault(File.Exists);
|
||||||
|
|
||||||
|
return commandPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue