C# 如何检查程序集(dll)的版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29772065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check the version of an assembly (dll)?
提问by user3229570
I have c# application and when I made a change, I am getting the error message:
我有 c# 应用程序,当我进行更改时,我收到错误消息:
An unhandled exception of type 'System.TypeLoadException' occurred in WindowsFormsApplication1.exe
Additional information: Could not load type
'TradeIdeas.TIProData.OddsMakerColumnConfiguration' from assembly 'TIProData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
WindowsFormsApplication1.exe 中发生类型为“System.TypeLoadException”的未处理异常
附加信息:无法
从程序集“TIProData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”加载类型“TradeIdeas.TIProData.OddsMakerColumnConfiguration”。
This message says the version number of dll (TIProData) is 1.0.0.0. I think there is a later version available. How can I tell the version number of a dll on my machine?
此消息表示 dll (TIProData) 的版本号为 1.0.0.0。我认为有可用的更高版本。如何知道我机器上的 dll 的版本号?
采纳答案by Patrick Hofman
You can use Reflector, ILDASMor ILSpyto get the assembly version.
You usually can find ILDASM in C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\ildasm.exe(where v8.1Ais the version of the Windows SDK installed).
您通常可以在C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\ildasm.exe(v8.1A安装的 Windows SDK 的版本在哪里)中找到 ILDASM 。
ILDASM:
伊尔达斯姆:


Reflector:
反射器:


回答by James Lucas
回答by PiotrWolkowski
There is a couple of ways to do it:
有几种方法可以做到:
If you reference the dll in Visual Studio right click it (in ProjectName/References folder) and select "Properties" you have "Version" and "Runtime Version" there.
In File Explorer when you right click the dll file and select properties there is a "File Version" and "Product Version" there.
Alternatively, investigate it in code:
Assembly assembly = Assembly.LoadFrom("TestAssembly.dll"); Version ver = assembly.GetName().Version;
如果您在 Visual Studio 中引用该 dll,请右键单击它(在 ProjectName/References 文件夹中)并选择“属性”,您在那里有“版本”和“运行时版本”。
在文件资源管理器中,当您右键单击 dll 文件并选择属性时,那里会出现“文件版本”和“产品版本”。
或者,在代码中调查它:
Assembly assembly = Assembly.LoadFrom("TestAssembly.dll"); Version ver = assembly.GetName().Version;
回答by Michael Freidgeim
If you know Class, that belongs to assembly, you can use GetTypeInfo
如果您知道属于程序集的 Class,则可以使用 GetTypeInfo
var?runtimeVersion =?typeof(MyClass)
.GetTypeInfo()
.Assembly
.GetCustomAttribute<AssemblyFileVersionAttribute>();
String ver=RuntimeVersion.Version; ?
String ver=RuntimeVersion.Version; ?
The example is for .Net Core from https://developers.de/blogs/damir_dobric/archive/2017/06/27/how-to-deal-with-assembly-version-in-net-core.aspx
该示例适用于来自https://developers.de/blogs/damir_dobric/archive/2017/06/27/how-to-deal-with-assembly-version-in-net-core.aspx 的.Net Core

