从 C# 读取非 .NET DLL 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/349943/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:07:22  来源:igfitidea点击:

Read a non .NET DLL version from C#?

c#dll

提问by Jon Tackabury

I have a folder with some DLLs in it (not .NET assemblies) and I would like to read the file information in them. Things like the version, name... etc. What is the best way to approach this?

我有一个文件夹,里面有一些 DLL(不是 .NET 程序集),我想读取其中的文件信息。诸如版本、名称等之类的东西。解决这个问题的最佳方法是什么?

采纳答案by Andrew Flanagan

Use the FileVersionInfo object. Here's an example from the Microsoft website that gets the version info from notepad.exe

使用 FileVersionInfo 对象。这是 Microsoft 网站上的一个示例,该示例从 notepad.exe 获取版本信息

public void GetFileVersion() {
    // Get the file version for the notepad.
    FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo("%systemroot%\Notepad.exe");

    // Print the file name and version number.
    textBox1.Text = "File: " + myFileVersionInfo.FileDescription + '\n' +
       "Version number: " + myFileVersionInfo.FileVersion;
 }

Stolen from here.

这里来的