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.)
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.)
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.
.ToString() to the end, e.g. [System.Reflection.Assembly]::LoadFrom("YourDllName.dll").GetName().Version.ToString()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.If you use mono and linux, try this:
monodis --assembly MyAssembly.dll
find . -name MyAssembly.dll -exec monodis --assembly {} ';' | grep Version
monodis, sudo apt-get install mono-utils.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));
}
}
}
}
for statement in Window batch to read output into variables. For example for /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.In Powershell
$version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("filepath.exe").FileVersion.ToString()
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)
Wow this is bad considering things like old exploitable gdiplus.dll's floating around.
My solution is simple. batch file programming.
This puts an nfo file in the same dir with the version
You can GET filever.exe, which can be downloaded as part of the Windows XP SP2 Support Tools package - only 4.7MB of download.
adobe_air_version.bat
c:\z\filever.exe /A /D /B "C:\Program Files\Common Files\Adobe AIR\Versions\1.0\Adobe AIR.dll" >000_adobe_air.dll_VERSION.nfo
exit
Variation.
Get all the versions in a directory to a text file.
c:\z\filever.exe /A /D /B "c:\somedirectory\ *.dll *.exe >000_file_versions.nfo
exit
There's also Sigcheck by systernals.
http://technet.microsoft.com/en-us/sysinternals/bb897441.aspx
If the intention is to see the version, we can use the following command
ildasm "<your assembly path>" /TEX | find "AssemblyFileVersionAttribute"
This return a string like the following .custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 0E 32 32 2E 38 2E 38 32 37 30 2E 31 36 35 // ...22.8.8270.165
The version is given in the comment.
File Version tool will help:
filever /V YourDllName.dll
I used the accepted answer in Windows PowerShell, but using Powershell 7 (pwsh) the accepted answer failed as follows:
[System.Reflection.Assembly]::LoadFrom($(Get-Location).Path + "\MyApp\bin\Debug\MyApp.exe").GetName().Version.ToString()
MethodInvocationException: Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'C:\Users\user\work\repo\MyApp\bin\Debug\MyApp.exe'. Format of the executable (.exe) or library (.dll) is invalid."
I cobbled together an alternative after reading the comments on this Reddit thread.
[System.Reflection.AssemblyName]::GetAssemblyName($(Get-Location).Path + "\MyApp\bin\Debug\MyApp.exe").Version.ToString()
3.1.9120.17056
Specifically [System.Reflection.Assembly]::LoadFrom() is loading into the .NET environment that PowerShell is running in - ie unless they are compatible it will fail to load.
Consider that LoadFrom() implies loading in preparation to run code from it, then we just query GetName() and throw it away. The alternative form just queries the metadata to get the name without loading via [System.Reflection.AssemblyName]::GetAssemblyName().
Do you use GACUTIL?
You can get the assembly version from this command below.
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe /L "<your assembly name>"