获取我的C#应用​​程序的版本? [英] Getting the Version of my C# app?

查看:92
本文介绍了获取我的C#应用​​程序的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理桌面应用程序.我已经创建了一个安装程序.

I am working on desktop application. I have create a setup.

例如我的应用程序.版本是1.0.0.

Ex. My Application. Version is 1.0.0.

我想获取我的桌面应用程序的当前版本为1.0.0.我已经尝试过使用Application.ProductVersion,但是它提供了控件的版本. (我正在使用DevExpress Control 15.2.7,因此它提供的当前版本为15.2.7.)

I want to get the current version of my desktop application which is 1.0.0. I have tried by using Application.ProductVersion but it provides the version of my controls. (I am using DevExpress Control15.2.7, so it provides the current version as 15.2.7).

如何获取已安装应用程序的当前版本?我想将其与已安装的版本进行比较,以为我的产品提供可用的新版本"功能.

How can I get the current version of the installed application? I want to compare it to the installed version to provide a "New Version Available" functionality for my product.

推荐答案

您要查找的信息位于 AssemblyInfo.cs 中.

The info you are looking for is in AssemblyInfo.cs.

要在运行时访问其中写入的信息,可以使用System.Reflection.Assembly.

To access the info written in there at runtime you can use the System.Reflection.Assembly.

使用System.Reflection.Assembly.GetExecutingAssembly()获取程序集(该行所在的 ),或使用System.Reflection.Assembly.GetEntryAssembly()获取项目开始的程序集(这很可能是您的应用程序).

Use System.Reflection.Assembly.GetExecutingAssembly() to get the assembly (that this line of code is in) or use System.Reflection.Assembly.GetEntryAssembly() to get the assembly your project started with (most likely this is your app).

在多项目解决方案中,这一点要牢记!

string version = Assembly.GetExecutingAssembly().GetName().Version.ToString()
// returns 1.0.0.0

对应的 AssemblyInfo.cs :

对应的 EXE属性:

在使用InstallShield时可能很重要(请参阅评论)!

This may be important when working with InstallShield (see comments) !

这篇关于获取我的C#应用​​程序的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆