如何以编程方式从Visual Studio安装项目中检索安装程序版本

时间:2022-05-01 07:01:31

I have written an application in C# and I have setup a separate Setup project to create the MSI installer for the app. I was wondering if it was possible to retrieve the version of the installer and display it in the About dialog in my application.

我在C#中编写了一个应用程序,我已经设置了一个单独的安装项目来为应用程序创建MSI安装程序。我想知道是否可以检索安装程序的版本并将其显示在我的应用程序的“关于”对话框中。

3 个解决方案

#1


In general you would look at the version of your current assembly for this kind of stuff, finding the MSI requires a registry search to find the MSI and then some interop to pull out the version using some COM interfaces.

一般情况下,你会看到当前程序集的这种类型的东西,发现MSI需要注册表搜索才能找到MSI,然后一些互操作来使用某些COM接口提取版本。

To get started along those lines have a look here: http://www.codeproject.com/KB/cs/msiinterop.aspx, it is a lot of work.

开始沿着这些方向看看这里:http://www.codeproject.com/KB/cs/msiinterop.aspx,这是很多工作。

Instead just use:

而只是使用:

Assembly.GetExecutingAssembly().GetName().Version;

And make sure you match your application version with your msi version.

并确保您的应用程序版本与您的msi版本相匹配。

#2


An MSI is like a database with a full API. Your version number and other releated data, live inside the MSI's database.

MSI就像一个带有完整API的数据库。您的版本号和其他相关数据存放在MSI的数据库中。

You could query the database using a sql like syntax.

您可以使用类似SQL的语法查询数据库。

http://msdn.microsoft.com/en-us/library/aa369426(VS.85).aspx

an example of how to query: http://msdn.microsoft.com/en-us/library/aa372021.aspx

如何查询的示例:http://msdn.microsoft.com/en-us/library/aa372021.aspx

better example and script:

更好的示例和脚本:

http://msdn.microsoft.com/en-us/library/aa368562(VS.85).aspx

#3


one idea is to store the installer version in registry or predefined in application.exe.config upon installation. Later About box load the version number from there.

一个想法是在安装时将安装程序版本存储在注册表中或在application.exe.config中预定义。稍后关于框从那里加载版本号。

#1


In general you would look at the version of your current assembly for this kind of stuff, finding the MSI requires a registry search to find the MSI and then some interop to pull out the version using some COM interfaces.

一般情况下,你会看到当前程序集的这种类型的东西,发现MSI需要注册表搜索才能找到MSI,然后一些互操作来使用某些COM接口提取版本。

To get started along those lines have a look here: http://www.codeproject.com/KB/cs/msiinterop.aspx, it is a lot of work.

开始沿着这些方向看看这里:http://www.codeproject.com/KB/cs/msiinterop.aspx,这是很多工作。

Instead just use:

而只是使用:

Assembly.GetExecutingAssembly().GetName().Version;

And make sure you match your application version with your msi version.

并确保您的应用程序版本与您的msi版本相匹配。

#2


An MSI is like a database with a full API. Your version number and other releated data, live inside the MSI's database.

MSI就像一个带有完整API的数据库。您的版本号和其他相关数据存放在MSI的数据库中。

You could query the database using a sql like syntax.

您可以使用类似SQL的语法查询数据库。

http://msdn.microsoft.com/en-us/library/aa369426(VS.85).aspx

an example of how to query: http://msdn.microsoft.com/en-us/library/aa372021.aspx

如何查询的示例:http://msdn.microsoft.com/en-us/library/aa372021.aspx

better example and script:

更好的示例和脚本:

http://msdn.microsoft.com/en-us/library/aa368562(VS.85).aspx

#3


one idea is to store the installer version in registry or predefined in application.exe.config upon installation. Later About box load the version number from there.

一个想法是在安装时将安装程序版本存储在注册表中或在application.exe.config中预定义。稍后关于框从那里加载版本号。