VB.net 获取 DLL 文件版本

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

VB.net Get DLL File Version

vb.netdllversiongetfileversion

提问by Anton King

Ive got a project that I have been tasked with, to install some Microsoft KB's, but they want me to check that once the KB has been installed, that it has update the DLL and the only way i can see they differ is by the DLL version.

我有一个项目,我的任务是安装一些 Microsoft KB,但他们希望我在安装 KB 后检查它是否更新了 DLL,我可以看到它们不同的唯一方法是 DLL版本。

Is there a way I can get VB.net to check the DLL file version (right click - properties - details - File Version)?

有没有办法让 VB.net 检查 DLL 文件版本(右键单击 - 属性 - 详细信息 - 文件版本)?

I have found a couple of things on the internet, but I cant get them to work or more likely I do not understand what I need to do to get the correct information.

我在互联网上找到了一些东西,但我无法让它们工作,或者更有可能我不明白我需要做什么才能获得正确的信息。

Any help with this would be great appreciated.

对此的任何帮助将不胜感激。

回答by John Janssen

http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.fileversion(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.fileversion(v=vs.110).aspx

This should give you some insight.

这应该会给你一些见解。

EDIT

编辑

I didn't add the code from the article, thought I would update the answer before the link was lost:

我没有添加文章中的代码,以为我会在链接丢失之前更新答案:

Imports System
Imports System.IO
Imports System.Diagnostics



Class Class1

    Public Shared Sub Main(ByVal args() As String)
    ' Get the file version for the notepad.
    ' Use either of the following two commands.
    FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe"))
    Dim myFileVersionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\Notepad.exe")


    ' Print the file name and version number.
    Console.WriteLine("File: " + myFileVersionInfo.FileDescription + vbLf + "Version number: " + myFileVersionInfo.FileVersion)

    End Sub
End Class

回答by Mike van Meeteren

After calling into a DLL, to ensure it's loaded, You can get the info from that DLL (all the stuff you'd see when right clicking on the DLL) using something like this:

在调用 DLL 后,为确保它已加载,您可以使用以下内容从该 DLL(右键单击 DLL 时看到的所有内容)获取信息:

Dim sModule As String

For Each tModule As ProcessModule In Process.GetCurrentProcess().Modules
  sModule = tModule.FileName
  If sModule.ToUpper.Contains(DLLFileName.ToUpper) Then
    Dim myFileVersionInfo As FileVersionInfo = _
           FileVersionInfo.GetVersionInfo(sModule)
    DLLFileAndVersion = sModule & " " & myFileVersionInfo.ProductVersion
  End If
Next