有没有微软工具可以从命令行获取 DLL 文件的程序集版本?
(我知道我可以编写自己的工具。)
有没有微软工具可以从命令行获取 DLL 文件的程序集版本?
(我知道我可以编写自己的工具。)
这是 PowerShell 突出的领域。如果你还没有安装它,请安装。它已经预装在 Windows 7 上。
运行以下命令行:
[System.Reflection.Assembly]::LoadFrom("C:\full\path\to\YourDllName.dll").GetName().Version
输出为:
Major Minor Build Revision
----- ----- ----- --------
3 0 8 0
请注意LoadFrom返回一个程序集对象,因此您可以做任何您想做的事情。不需要编写程序。.ToString()
,例如[System.Reflection.Assembly]::LoadFrom("YourDllName.dll").GetName().Version.ToString()
。 - Rich Zwaap如果你使用的是Mono和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));
}
}
}
}
for
语句来读取输出到变量中。例如,for /f %%a in ('time /t') do ( set currentTime=%%a )
会在循环内将时间读入%%a
,然后将其设置为%currentTime%
,随后您可以使用它。 - Paul Ruane在Powershell中
$version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("filepath.exe").FileVersion.ToString()
我使用了选定的答案,直到出现以下错误:不能为执行加载引用程序集。它们只能在仅反射加载器上下文中加载。
这个错误出现在多个程序集中。
使用
[System.Reflection.Assembly]::ReflectionOnlyLoadFrom("C:\full\path\to\YourDllName.dll").GetName().Version
哇,考虑到像旧的可利用的gdiplus.dll之类的东西,这真是太糟糕了。
我的解决方案很简单。批处理编程。
这将在相同的目录中放置一个nfo文件与版本一起。
您可以获取filever.exe,它可以作为Windows XP SP2支持工具包的一部分下载 - 仅需下载4.7MB。
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
变体。
将目录中的所有版本保存到文本文件中。
c:\z\filever.exe /A /D /B "c:\somedirectory\ *.dll *.exe >000_file_versions.nfo
exit
还有Systernals的Sigcheck。
http://technet.microsoft.com/en-us/sysinternals/bb897441.aspx
在其他 PowerShell 风格的答案中添加一些糖...
获取扩展属性,如“FullName”
$dllPath = "C:\full\path\to\YourDllName.dll";
$ass = [System.Reflection.Assembly]::LoadFrom($dllPath);
$ass.GetName();
$ass
文件版本工具将会有所帮助:
filever /V YourDllName.dll
ildasm "<your assembly path>" /TEX | find "AssemblyFileVersionAttribute"
这将返回一个类似以下的字符串 .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
版本号在注释中给出。
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe /L "<your assembly name>"