diff --git a/PlexCleaner/Program.cs b/PlexCleaner/Program.cs index 21e7848a..107b7f62 100644 --- a/PlexCleaner/Program.cs +++ b/PlexCleaner/Program.cs @@ -73,13 +73,29 @@ private static int Main() return exitCode; } + public static string GetVersion(bool versionOnly) + { + var assembly = Assembly.GetEntryAssembly(); + assembly ??= Assembly.GetExecutingAssembly(); + + var versionAttribute = assembly.GetCustomAttribute(); + + string version = versionAttribute?.InformationalVersion; + version ??= assembly.GetName()?.Version?.ToString(); + version ??= "?"; + + string name = assembly.GetName()?.Name; + name ??= "?"; + + return versionOnly ? version : $"{name} : {version}"; + } + private static bool ShowVersionInformation() { // Use the raw commandline and look for --version if (Environment.CommandLine.Contains("--version")) { - string appVersion = Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion; - Console.WriteLine(appVersion); + Console.WriteLine(GetVersion(false)); return true; } return false; @@ -496,9 +512,7 @@ private static Program Create(CommandLineOptions options, bool verifyTools) #else const bool debugBuild = false; #endif - string appVersion = Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion; - string runtimeVersion = Environment.Version.ToString(); - Log.Logger.Information("Application Version : {AppVersion}, Runtime Version : {RuntimeVersion}, Debug Build: {DebugBuild}", appVersion, runtimeVersion, debugBuild); + Log.Logger.Information("Application Version : {AppVersion}, Runtime Version : {RuntimeVersion}, Debug Build: {DebugBuild}", GetVersion(true), Environment.Version.ToString(), debugBuild); // Parallel processing config if (Options.Parallel)