Assembly version from command line?
Solution 1
This is an area where PowerShell shines. If you don't already have it, install it. It's preinstalled with Windows 7.
Running this command line:
[System.Reflection.Assembly]::LoadFrom("C:\full\path\to\YourDllName.dll").GetName().Version
outputs this:
Major Minor Build Revision
----- ----- ----- --------
3 0 8 0
Note that LoadFrom returns an assembly object, so you can do pretty much anything you like. No need to write a program.
Solution 2
If you use mono and linux, try this:
monodis --assembly MyAssembly.dll
find . -name MyAssembly.dll -exec monodis --assembly {} ';' | grep Version
Solution 3
For those, like I, who come looking for such a tool:
using System;
using System.IO;
using System.Reflection;
class Program
{
public static void Main(string[] args)
{
foreach (string arg in args)
{
try
{
string path = Path.GetFullPath(arg);
var assembly = Assembly.LoadFile(path);
Console.Out.WriteLine(assembly.GetName().FullName);
}
catch (Exception exception)
{
Console.Out.WriteLine(string.Format("{0}: {1}", arg, exception.Message));
}
}
}
}
Solution 4
In Powershell
$version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("filepath.exe").FileVersion.ToString()
Solution 5
I used the selected answer until I got the following error
Reference assemblies should not be loaded for
execution. They can only be loaded in the Reflection-only loader context.
for several assemblies
using
[System.Reflection.Assembly]::ReflectionOnlyLoadFrom("C:\full\path\to\YourDllName.dll").GetName().Version
should work in those cases (probably all cases)
Patrice Pezillier
Updated on May 23, 2020Comments
-
Patrice Pezillier almost 4 years
Is there a Microsoft tool to get the assembly version of a DLL file from a command line?
(I know that I can code my own tool.)
-
Piotr Owsiak over 12 yearsSuch short pieces of code are best (and easiest to maintain) when kept as scripts. I highly recommend the cs-script project to achive this.
-
OregonGhost almost 12 yearsI would expect it to work similarly. My tests failed, though, with an error message that says that the runtime version of the mixed-mode assembly is newer than the one loaded - don't know how to circumvent this.
-
JJS almost 10 years/l [ <assembly_name> ] Lists the contents of the global assembly cache. When the optional <assembly_name> parameter is specified only matching assemblies are listed.
-
Brannon almost 10 yearsWhat and where is this?
-
laifukang over 9 yearsIt is in Windows XP Service Pack 2 Support Tools. HOWEVER, this can only be installed on an XP system. SO, to get the file for Win7/8, 'unzip' the installation exe with a tool like 7-Zip. Extract the 'support.cab' file inside. Then yet again, unpack this CAB using 7-Zip and you can get 'filever.exe'.
-
Rich Zwaap over 9 yearsTo get only the version number, append
.ToString()
to the end, e.g.[System.Reflection.Assembly]::LoadFrom("YourDllName.dll").GetName().Version.ToString()
-
Matt almost 8 yearsGood answer. Q: How can I use that in the external tools of Visual Studio (Tools -> External Tools...) ?
-
Matt almost 8 yearsThat does not work for me if I have a local assembly, e.g. inside a NUGET package. Gacutil only works for assemblies in the GAC.
-
Richard P almost 7 yearsA couple of caveats to this solution. 1) It takes the full path to the DLL. The relative path in the example won't work. 2) It marks the assembly as "in use", which prevents it from being replaced until you exit that powershell process. That can block a build or deleting the folder, etc. To get around that either do it in a script or invoke "powershell" one more time first, then exit that child-process powershell when done.
-
GregHNZ almost 7 yearsFor me on Windows 10, it would not recognise double quotes, and reported
Missing ')' in method call
then complained about the filename. It works fine, however, using single quotes. Also, on Windows 10 with single-quotes it will accept a relative path. -
OzBob over 5 yearsadd GetName() and see extended properties. See fuller example in my answer
-
Carl Walsh over 5 yearsThe FileVersion is different than the AssemblyVersion
-
whatsisname about 5 yearsThis answer will frequently no longer work because of .net runtime version mismatch shenanigans.
-
NickG about 4 yearsIs there any way to use this to get the output in a batch file variable?
-
Paul Ruane almost 3 years@NickG, you can (mis)use the
for
statement in Window batch to read output into variables. For examplefor /f %%a in ('time /t') do ( set currentTime=%%a )
would read the time into%%a
within the loop then set it into%currentTime%
where you can subsequently use it. -
cskwg over 2 yearsSigCheck is VERY nice, but it does not show AssemblyVersion.