简体   繁体   English

如何在Visual Studio WPF中绑定“发布版本”属性

[英]How to bind the “publish version” property in visual studio WPF

When I'm using the publish option in Visual Studio to create an .*exe package of my application, I can change the Publish Version and it starts from 1.0.0.0. 当我在Visual Studio中使用发布选项创建应用程序的。* exe程序包时,可以更改发布版本 ,它从1.0.0.0开始。

Every time I'm changing something and re-publish it, the version number is increment automatically, and I want to bind that property to a TextBlock in my WPF. 每次更改并重新发布时,版本号都会自动递增,并且我想将该属性绑定到WPF中的TextBlock。

How can I do that? 我怎样才能做到这一点? Thank you. 谢谢。

在此处输入图片说明

First of all you have to reference in your project to System.Deployment.dll than you can try this code: 首先,您必须在项目中引用System.Deployment.dll ,然后才能尝试以下代码:

    public string PublishVersion
    {
        get
        {
            if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
            {
                Version ver = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion;
                return string.Format("{0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision);
            }
            else
            {
                return "Not Published";
            }
        }
    }

Remember that will be work only when you have installed your app. 请记住,只有在安装了应用程序后,该功能才起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM