Fix incorrect default executable name for .NET Core apps

This commit is contained in:
Alexey Golub
2019-08-19 22:02:19 +03:00
parent 4b98dbf51f
commit 3017c3d6c3

View File

@@ -93,30 +93,39 @@ namespace CliFx
if (_title.IsNullOrWhiteSpace()) if (_title.IsNullOrWhiteSpace())
{ {
// Entry assembly is null in tests // Entry assembly is null in tests
var title = EntryAssembly?.GetName().Name ?? "App"; UseTitle(EntryAssembly?.GetName().Name ?? "App");
UseTitle(title);
} }
if (_executableName.IsNullOrWhiteSpace()) if (_executableName.IsNullOrWhiteSpace())
{ {
// Entry assembly is null in tests // Entry assembly is null in tests
var entryAssemblyLocation = EntryAssembly?.Location; var entryAssemblyLocation = EntryAssembly?.Location;
var executableName = Path.GetFileNameWithoutExtension(entryAssemblyLocation) ?? "app";
// Set proper executable name for apps launched with dotnet SDK // Set different executable name depending on location
if (string.Equals(Path.GetExtension(entryAssemblyLocation), ".dll", StringComparison.OrdinalIgnoreCase)) if (!entryAssemblyLocation.IsNullOrWhiteSpace())
executableName = "dotnet " + executableName; {
// Prepend 'dotnet' to assembly file name if the entry assembly is a dll file (extension needs to be kept)
UseExecutableName(executableName); if (string.Equals(Path.GetExtension(entryAssemblyLocation), ".dll", StringComparison.OrdinalIgnoreCase))
{
UseExecutableName("dotnet " + Path.GetFileName(entryAssemblyLocation));
}
// Otherwise just use assembly file name without extension
else
{
UseExecutableName(Path.GetFileNameWithoutExtension(entryAssemblyLocation));
}
}
// If location is null then just use a stub
else
{
UseExecutableName("app");
}
} }
if (_versionText.IsNullOrWhiteSpace()) if (_versionText.IsNullOrWhiteSpace())
{ {
// Entry assembly is null in tests // Entry assembly is null in tests
var versionText = EntryAssembly?.GetName().Version.ToString() ?? "1.0"; UseVersionText(EntryAssembly?.GetName().Version.ToString() ?? "1.0");
UseVersionText(versionText);
} }
if (_console == null) if (_console == null)