mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Set proper default executable name for apps launched with dotnet SDK
This commit is contained in:
@@ -12,7 +12,7 @@ namespace CliFx
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default implementation of <see cref="ICliApplicationBuilder"/>.
|
/// Default implementation of <see cref="ICliApplicationBuilder"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CliApplicationBuilder : ICliApplicationBuilder
|
public partial class CliApplicationBuilder : ICliApplicationBuilder
|
||||||
{
|
{
|
||||||
private readonly HashSet<Type> _commandTypes = new HashSet<Type>();
|
private readonly HashSet<Type> _commandTypes = new HashSet<Type>();
|
||||||
|
|
||||||
@@ -90,23 +90,44 @@ namespace CliFx
|
|||||||
|
|
||||||
private void SetFallbackValues()
|
private void SetFallbackValues()
|
||||||
{
|
{
|
||||||
// Entry assembly is null in tests
|
|
||||||
var entryAssembly = Assembly.GetEntryAssembly();
|
|
||||||
|
|
||||||
if (_title.IsNullOrWhiteSpace())
|
if (_title.IsNullOrWhiteSpace())
|
||||||
UseTitle(entryAssembly?.GetName().Name ?? "App");
|
{
|
||||||
|
// Entry assembly is null in tests
|
||||||
|
var title = EntryAssembly?.GetName().Name ?? "App";
|
||||||
|
|
||||||
|
UseTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
if (_executableName.IsNullOrWhiteSpace())
|
if (_executableName.IsNullOrWhiteSpace())
|
||||||
UseExecutableName(Path.GetFileNameWithoutExtension(entryAssembly?.Location) ?? "app");
|
{
|
||||||
|
// Entry assembly is null in tests
|
||||||
|
var entryAssemblyLocation = EntryAssembly?.Location;
|
||||||
|
var executableName = Path.GetFileNameWithoutExtension(entryAssemblyLocation) ?? "app";
|
||||||
|
|
||||||
|
// Set proper executable name for apps launched with dotnet SDK
|
||||||
|
if (string.Equals(Path.GetExtension(entryAssemblyLocation), ".dll", StringComparison.OrdinalIgnoreCase))
|
||||||
|
executableName = "dotnet " + executableName;
|
||||||
|
|
||||||
|
UseExecutableName(executableName);
|
||||||
|
}
|
||||||
|
|
||||||
if (_versionText.IsNullOrWhiteSpace())
|
if (_versionText.IsNullOrWhiteSpace())
|
||||||
UseVersionText(entryAssembly?.GetName().Version.ToString() ?? "1.0");
|
{
|
||||||
|
// Entry assembly is null in tests
|
||||||
|
var versionText = EntryAssembly?.GetName().Version.ToString() ?? "1.0";
|
||||||
|
|
||||||
|
UseVersionText(versionText);
|
||||||
|
}
|
||||||
|
|
||||||
if (_console == null)
|
if (_console == null)
|
||||||
|
{
|
||||||
UseConsole(new SystemConsole());
|
UseConsole(new SystemConsole());
|
||||||
|
}
|
||||||
|
|
||||||
if (_commandFactory == null)
|
if (_commandFactory == null)
|
||||||
|
{
|
||||||
UseCommandFactory(new CommandFactory());
|
UseCommandFactory(new CommandFactory());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -124,4 +145,11 @@ namespace CliFx
|
|||||||
_commandFactory, new CommandInitializer(), new HelpTextRenderer());
|
_commandFactory, new CommandInitializer(), new HelpTextRenderer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public partial class CliApplicationBuilder
|
||||||
|
{
|
||||||
|
private static readonly Lazy<Assembly> LazyEntryAssembly = new Lazy<Assembly>(Assembly.GetEntryAssembly);
|
||||||
|
|
||||||
|
private static Assembly EntryAssembly => LazyEntryAssembly.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user