Patrice Pezillier
Patrice Pezillier

Reputation: 4586

Assembly version from command line?

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.)

Upvotes: 74

Views: 58325

Answers (11)

Greg
Greg

Reputation: 2729

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().

Upvotes: 0

Pramod B R
Pramod B R

Reputation: 652

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.

Upvotes: 0

OregonGhost
OregonGhost

Reputation: 23759

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.

Upvotes: 109

OzBob
OzBob

Reputation: 4530

Adding some sugar to the other powershell-ish answers...

To get extended properties like 'FullName'

$dllPath = "C:\full\path\to\YourDllName.dll";
$ass  = [System.Reflection.Assembly]::LoadFrom($dllPath);
$ass.GetName();
$ass

Upvotes: 0

gilmishal
gilmishal

Reputation: 2022

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)

Upvotes: 5

Paul Ruane
Paul Ruane

Reputation: 38620

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));
            }
        }
    }
}

Upvotes: 11

Aussie Ash
Aussie Ash

Reputation: 1336

In Powershell

$version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("filepath.exe").FileVersion.ToString()

Upvotes: 8

Radityo Ardi
Radityo Ardi

Reputation: 138

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>"

Upvotes: -3

head_thrash
head_thrash

Reputation: 1711

If you use mono and linux, try this:

monodis --assembly MyAssembly.dll

find . -name MyAssembly.dll -exec monodis --assembly {} ';' | grep Version 

Upvotes: 21

Antony Thomas
Antony Thomas

Reputation: 3696

File Version tool will help:

filever /V YourDllName.dll

Upvotes: 0

Tail-Gunner
Tail-Gunner

Reputation: 27

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

Upvotes: 1

Related Questions