Assembly version from command line?

2019-01-21 09:00发布

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

9条回答
劫难
2楼-- · 2019-01-21 09:33

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)

查看更多
beautiful°
3楼-- · 2019-01-21 09:40

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));
            }
        }
    }
}
查看更多
来,给爷笑一个
4楼-- · 2019-01-21 09:40

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>"
查看更多
登录 后发表回答