如何在.NET ClickOnce应用程序中将发布版本同步到程序集版本? [英] How to synchronise the publish version to the assembly version in a .NET ClickOnce application?

查看:82
本文介绍了如何在.NET ClickOnce应用程序中将发布版本同步到程序集版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C#ClickOnce应用程序中,项目-> 属性-> 发布选项卡中有一个自动递增的发布版本.我想在菜单 Help -> About 框中显示该版本,但是我正在使用的代码显然访问了程序集Version,这是不同的.

程序集版本可以在项目-> 属性-> 应用程序->程序集信息对话框中手动更改.因此,就目前而言,每次发布之前,我都会将发布版本复制到程序集版本,因此我的对话框会显示当前的版本 应用程序.必须有更好的方法来做到这一点.

我真正想做的就是拥有一个准确的,自动更新的,可通过代码访问的版本号.

这是我用来访问程序集版本号的代码:

public string AssemblyVersion
{
    get
    {
        return Assembly.GetExecutingAssembly().GetName().Version.ToString();
    }
}

一种替代方法是查找访问发布版本的代码.

根据我的经验,

解决方案

sylvanaar的最后一行看起来像是要走的路.但要注意的是,它仅适用于应用程序的已部署版本.出于调试目的,您可能需要以下内容:

    static internal string GetVersion()
    {
        if (ApplicationDeployment.IsNetworkDeployed)
        {
            return ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
        }

        return "Debug";
    }

In my C# ClickOnce application, there is an auto-incremented publish version in the Project -> Properties -> Publish tab. I'd like to display that version in my menu Help -> About box, but the code I'm using apparently accesses the assembly Version, which is different.

The Assembly Version can be changed manually in the Project -> Properties -> Application -> Assembly Information dialog. So for now, every time before I publish I've been copying the publish version to the assembly version, so my dialog shows the current version of the application. There must be a better way to do this.

All I really want to do is have an accurate, auto-updated, code-accessible version number.

Here's the code I'm using to access the assembly version number:

public string AssemblyVersion
{
    get
    {
        return Assembly.GetExecutingAssembly().GetName().Version.ToString();
    }
}

An alternative would be to find code that accesses the publish version.

解决方案

sylvanaar's last line looks like the way to go, in my experience; but with the caveat that it is only available to deployed versions of the application. For debugging purposes, you might want something like:

    static internal string GetVersion()
    {
        if (ApplicationDeployment.IsNetworkDeployed)
        {
            return ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
        }

        return "Debug";
    }

这篇关于如何在.NET ClickOnce应用程序中将发布版本同步到程序集版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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