如何在C#中获取当前产品版本? [英] How to get the current product version in C#?

查看:306
本文介绍了如何在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();
    }
} 

这篇关于如何在C#中获取当前产品版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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