visual-studio 如何获取 ClickOnce 发布版本以匹配 AssemblyInfo.cs 文件版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get the ClickOnce Publish version to match the AssemblyInfo.cs File version?
提问by Kris Erickson
Every time I publish the application in ClickOnceI 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)?
每次我在ClickOnce 中发布应用程序时,我都会将修订号更新一。有没有办法自动获取此更改以更改 AssemblyInfo.cs 文件中的版本号(我们所有的错误报告都查看程序集版本)?
回答by Jason Stangroome
We use Team Foundation Server Team Build and have added a block to the TFSBuild.proj's AfterCompiletarget to trigger the ClickOnce publish with our preferred version number:
我们使用 Team Foundation Server Team Build 并向 TFSBuild.proj 的AfterCompile目标添加了一个块,以使用我们首选的版本号触发 ClickOnce 发布:
<MSBuild Projects="$(SolutionRoot)\MyProject\Myproject.csproj"
Properties="PublishDir=$(OutDir)\myProjectPublish\;
ApplicationVersion=$(PublishApplicationVersion);
Configuration=$(Configuration);Platform=$(Platform)"
Targets="Publish" />
The PublishApplicationVersionvariable is generated by a custom MSBuild task to use the TFS Changeset number, but you could use your own custom taskor an existing solutionto get the version number from the AssemblyInfo file.
该PublishApplicationVersion变量由自定义 MSBuild 任务生成以使用 TFS 变更集编号,但您可以使用自己的自定义任务或现有解决方案从 AssemblyInfo 文件中获取版本号。
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.
这理论上可以在您的项目文件中完成(无论如何它只是一个 MSBuild 脚本),但我建议不要从开发人员机器部署。
I'm sure other continuous integration(CI) solutions can handle this similarly.
我确信其他持续集成(CI) 解决方案可以类似地处理这个问题。
Edit: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 版本号到 AssemblyInfo 文件应该是可行的。我确信 MSBuild 社区任务(上面的链接)有一个更新 AssemblyInfo 文件的任务,所以你只需要一个自定义任务来从 ClickOnce 配置 XML 中提取版本号。
However, you may also consider changing your error reporting to include the ClickOnce publish version too:
但是,您也可以考虑更改错误报告以包含 ClickOnce 发布版本:
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
Debug.WriteLine(System.Deployment.Application.ApplicationDeployment.
CurrentDeployment.CurrentVersion);
}
回答by Todd
I implemented this recently using some custom tasks. An issue I found with implementing this with ClickOnce is that all your DLL files are updated. This causes the ClickOnce update to download all the application files every update. This bypasses on of the nice features of the ClickOnce deployment where only the modified files are re-downloaded in an update.
我最近使用一些自定义任务实现了这一点。我在使用 ClickOnce 实现此功能时发现的一个问题是所有 DLL 文件都已更新。这会导致 ClickOnce 更新在每次更新时下载所有应用程序文件。这绕过了 ClickOnce 部署的一些不错的功能,其中只有修改过的文件会在更新中重新下载。
Just something to think about when implementing something like this with ClickOnce.
只是在使用 ClickOnce 实现这样的事情时需要考虑的事情。
回答by Rinat Abdullin
Steps:
脚步:
- Use external incrementing version number (if you leverage a continuous integration server like CruiseControl.NET, then it comes from the build label).
- Use GlobalVersionInfo.cs (file link-referenced by all projects in your solution) to hold the current version and update it on the build with the AssemblyInfo task from the MSBuild Communitytasks.
- Script Magecommand-line tool from the .NET SDK to update the ClickOnce manifest, using the same version (see the
-vand-mvswitches).
- 使用外部递增版本号(如果您利用像 CruiseControl.NET 这样的持续集成服务器,那么它来自构建标签)。
- 使用 GlobalVersionInfo.cs(由解决方案中的所有项目链接引用的文件)保存当前版本,并使用MSBuild 社区任务中的 AssemblyInfo 任务在构建中更新它。
- .NET SDK 中的Script Mage命令行工具,用于更新 ClickOnce 清单,使用相同版本(请参阅
-v和-mv开关)。
BTW, a nice bonus is that, whenever you automatically publish a newer ClickOnce deployment version via the integration script, if you also specify the minimal version to mage.exe (same as version), then every user will be updated automatically on the next application launch.
顺便说一句,一个不错的好处是,每当您通过集成脚本自动发布更新的 ClickOnce 部署版本时,如果您还指定 mage.exe 的最低版本(与版本相同),那么每个用户都将在下一个应用程序中自动更新发射。
回答by Judah Gabriel Himango
You'll probably need to create a piece of code that updates AssemblyInfo.cs according to the version number stored in the .csproj file. (The ClickOnce deploy version is stored inside an XML tag.)
您可能需要创建一段代码,根据 .csproj 文件中存储的版本号更新 AssemblyInfo.cs。(ClickOnce 部署版本存储在 XML 标记中。)
You'd then change your .csproj file to run this bit of code when Publish|Release build is performed. The MSBuild folks have blogged about how to perform custom actions during certain build types; check the MSBuild team blog.
然后,您将更改 .csproj 文件以在执行发布|发布构建时运行这段代码。MSBuild 人员在博客中介绍了如何在某些构建类型期间执行自定义操作;查看MSBuild 团队博客。

