From 7a87e553b6ec8b56278d6b88d3beb22d443aa929 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 11 Dec 2017 08:49:18 +0100 Subject: [PATCH] Surface decompiler version in both console and ps cmdlets (intended for user error reporting) --- ICSharpCode.Decompiler.Console/Program.cs | 2 ++ ICSharpCode.Decompiler.Console/Publish.cmd | 3 +++ ICSharpCode.Decompiler.PowerShell/Demo.ps1 | 3 +++ .../GetDecompilerVersion.cs | 16 ++++++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 ICSharpCode.Decompiler.Console/Publish.cmd create mode 100644 ICSharpCode.Decompiler.PowerShell/GetDecompilerVersion.cs diff --git a/ICSharpCode.Decompiler.Console/Program.cs b/ICSharpCode.Decompiler.Console/Program.cs index 319480052..1b375003f 100644 --- a/ICSharpCode.Decompiler.Console/Program.cs +++ b/ICSharpCode.Decompiler.Console/Program.cs @@ -17,6 +17,7 @@ namespace ICSharpCode.Decompiler.Console // Older cmd line clients (for options reference): https://github.com/aerror2/ILSpy-For-MacOSX and https://github.com/andreif/ILSpyMono var app = new CommandLineApplication(); + app.LongVersionGetter = () => "ilspycmd " + typeof(FullTypeName).Assembly.GetName().Version.ToString(); app.HelpOption("-h|--help"); var inputAssemblyFileName = app.Argument("Assembly filename name", "The assembly that is being decompiled. This argument is mandatory."); var projectOption = app.Option("-p|--project", "Decompile assembly as compilable project. This requires the output directory option.", CommandOptionType.NoValue); @@ -31,6 +32,7 @@ namespace ICSharpCode.Decompiler.Console // HACK : the CommandLineUtils package does not allow us to specify an argument as mandatory. // Therefore we're implementing it as simple as possible. if (inputAssemblyFileName.Value == null) { + app.ShowVersion(); app.ShowHint(); return -1; } diff --git a/ICSharpCode.Decompiler.Console/Publish.cmd b/ICSharpCode.Decompiler.Console/Publish.cmd new file mode 100644 index 000000000..1e99ab006 --- /dev/null +++ b/ICSharpCode.Decompiler.Console/Publish.cmd @@ -0,0 +1,3 @@ +dotnet publish -c release -r win7-x64 +dotnet publish -c release -r osx-x64 +dotnet publish -c release -r linux-x64 \ No newline at end of file diff --git a/ICSharpCode.Decompiler.PowerShell/Demo.ps1 b/ICSharpCode.Decompiler.PowerShell/Demo.ps1 index 36674d23c..04e2ae618 100644 --- a/ICSharpCode.Decompiler.PowerShell/Demo.ps1 +++ b/ICSharpCode.Decompiler.PowerShell/Demo.ps1 @@ -7,6 +7,9 @@ if ([string]::IsNullOrEmpty($basePath)) $modulePath = $basePath + '\bin\Debug\netstandard2.0\ICSharpCode.Decompiler.Powershell.dll' Import-Module $modulePath +$version = Get-DecompilerVersion +Write-Output $version + $decompiler = Get-Decompiler $modulePath $classes = Get-DecompiledTypes $decompiler -Types class diff --git a/ICSharpCode.Decompiler.PowerShell/GetDecompilerVersion.cs b/ICSharpCode.Decompiler.PowerShell/GetDecompilerVersion.cs new file mode 100644 index 000000000..51ee9a1cd --- /dev/null +++ b/ICSharpCode.Decompiler.PowerShell/GetDecompilerVersion.cs @@ -0,0 +1,16 @@ +using System; +using System.Management.Automation; +using ICSharpCode.Decompiler.TypeSystem; + +namespace ICSharpCode.Decompiler.PowerShell +{ + [Cmdlet(VerbsCommon.Get, "DecompilerVersion")] + [OutputType(typeof(string))] + public class GetDecompilerVersion : PSCmdlet + { + protected override void ProcessRecord() + { + WriteObject(typeof(FullTypeName).Assembly.GetName().Version.ToString()); + } + } +}