如何在C#中获取当前产品版本?
问题描述:
如何以C#方式以编程方式获取当前产品版本?
How can I programmatically get the current product version in C#?
我的代码:
VersionNumber = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
我正在获取VersionNumber = 1.0.0.0,但是当前版本是1.0.0.12。
I am getting VersionNumber=1.0.0.0, but the current version is 1.0.0.12.
答
我得到了我的问题的答案,它只是提供对System.Deployment.Application的引用,尽管它在视觉开发中不起作用Studio,但是一旦部署了应用程序,它将可以正常工作。
I got the answer to my question its Just give the reference to System.Deployment.Application and though it wont work in developement of the visual studio but it will work once the application is deployed.
//using System.Deployment.Application;
//using System.Reflection;
public string CurrentVersion
{
get
{
return ApplicationDeployment.IsNetworkDeployed
? ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString()
: Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}