如何获得ClickOnce发布版本以匹配AssemblyInfo.cs文件版本? [英] How do I get the ClickOnce Publish version to match the AssemblyInfo.cs File version?

查看:86
本文介绍了如何获得ClickOnce发布版本以匹配AssemblyInfo.cs文件版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我在 ClickOnce 中发布应用程序都会得到更新版本号的信息。一个。有没有一种方法可以自动进行此更改以更改AssemblyInfo.cs文件中的版本号(我们所有的错误报告都将查看程序集版本)?

Every time I publish the application in ClickOnce I get get it to update the revision number by one. Is there a way to get this change automatically to change the version number in AssemblyInfo.cs file (all our error reporting looks at the Assembly Version)?

推荐答案

我们使用Team Foundation Server Team Build,并在TFSBuild.proj的 AfterCompile 目标中添加了一个块,以触发具有我们首选版本号的ClickOnce发布:

We use Team Foundation Server Team Build and have added a block to the TFSBuild.proj's AfterCompile target to trigger the ClickOnce publish with our preferred version number:

<MSBuild Projects="$(SolutionRoot)\MyProject\Myproject.csproj"
         Properties="PublishDir=$(OutDir)\myProjectPublish\;
                     ApplicationVersion=$(PublishApplicationVersion);
                     Configuration=$(Configuration);Platform=$(Platform)"
         Targets="Publish" />

PublishApplicationVersion 变量由自定义生成MSBuild任务以使用TFS变更集编号,但是您可以使用您自己的自定义任务现有解决方案,以从AssemblyInfo文件中获取版本号。

The PublishApplicationVersion variable is generated by a custom MSBuild task to use the TFS Changeset number, but you could use your own custom task or an existing solution to get the version number from the AssemblyInfo file.

从理论上讲,这可以在您的项目文件中完成(无论如何,这只是一个MSBuild脚本),但是我建议您不要从开发人员机器上进行部署。

This could theoretically be done in your project file (which is just an MSBuild script anyway), but I'd recommend against deploying from a developer machine.

我确定其他连续集成(CI)解决方案都可以类似地处理。

I'm sure other continuous integration (CI) solutions can handle this similarly.

编辑:抱歉,问题倒退了。从ClickOnce版本号转到AssemblyInfo文件应该是可行的。我确定MSBuild社区任务(上面的链接)具有更新AssemblyInfo文件的任务,因此您只需要一个自定义任务即可从ClickOnce配置XML中提取版本号。

Sorry, got your question backwards. Going from the ClickOnce version number to the AssemblyInfo file should be doable. I'm sure the MSBuild Community Tasks (link above) have a task for updating the AssemblyInfo file, so you'd just need a custom task to pull the version number from the ClickOnce configuration XML.

但是,您也可以考虑更改错误报告,使其也包括ClickOnce发布版本:

However, you may also consider changing your error reporting to include the ClickOnce publish version too:

if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
    Debug.WriteLine(System.Deployment.Application.ApplicationDeployment.
                                                        CurrentDeployment.CurrentVersion);
}

这篇关于如何获得ClickOnce发布版本以匹配AssemblyInfo.cs文件版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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