IT story

명령 줄의 어셈블리 버전?

hot-time 2021. 1. 6. 20:26
반응형

명령 줄의 어셈블리 버전?


명령 줄에서 DLL 파일의 어셈블리 버전을 가져 오는 Microsoft 도구가 있습니까?

(내 자신의 도구를 코딩 할 수 있다는 것을 알고 있습니다.)


이것은 PowerShell이 ​​빛나는 영역입니다. 아직 설치하지 않은 경우 설치하십시오. Windows 7과 함께 사전 설치되어 있습니다.

이 명령 줄 실행 :

[System.Reflection.Assembly]::LoadFrom("C:\full\path\to\YourDllName.dll").GetName().Version

다음을 출력합니다.

Major  Minor  Build  Revision
-----  -----  -----  --------
3      0      8      0

LoadFrom은 어셈블리 개체를 반환하므로 원하는 모든 작업을 수행 할 수 있습니다. 프로그램을 작성할 필요가 없습니다.


모노 및 Linux를 사용하는 경우 다음을 시도하십시오.

monodis --assembly MyAssembly.dll

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

저와 같은 도구를 찾고있는 사람들을 위해 :

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

Powershell에서

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

Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context.여러 어셈블리에 대해 다음 오류가 발생할 때까지 선택한 답변을 사용했습니다.

사용

[System.Reflection.Assembly]::ReflectionOnlyLoadFrom("C:\full\path\to\YourDllName.dll").GetName().Version

이러한 경우에 작동해야합니다 (아마 모든 경우).


와우, 오래된 악용 가능한 gdiplus.dll이 떠 다니는 것과 같은 것들을 고려할 때 이것은 나쁩니다.

내 솔루션은 간단합니다. 배치 파일 프로그래밍.

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


File Version tool will help:

filever /V YourDllName.dll

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

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

ReferenceURL : https://stackoverflow.com/questions/3037008/assembly-version-from-command-line

반응형