使用MSBuild命令行指定发布版本为项目的程序集版本 [英] Specify publish version with MSBuild command line as assembly version of project

查看:592
本文介绍了使用MSBuild命令行指定发布版本为项目的程序集版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的批处理文件,该文件是从DOS命令行运行的,该文件用于构建发布 ClickOnce 项目.一行是这样的:

I have a simple batch file that I'm running from a DOS command line that is used for building a small C# application that publishes a ClickOnce project. One line is this:

msbuild MyApp.csproj /t:publish /property:PublishDir="deploy/"

当前会发布该应用程序,但它使用我在Visual Studio的发布"选项卡中设置的发布版本.我希望能够在命令行上设置发布版本,特别是,我想使用项目的 Assembly Version .像这样:

This currently publishes the application, but it uses the Publish Version that I set up in Visual Studio's "Publish" tab. I'm hoping to be able to set the publish version at the command line, and specifically, I'd like to use the Assembly Version of the project. Something like:

msbuild MyApp.csproj /t:publish /property:PublishDir="deploy/" /property:PublishVersion="$(Proj.AssemblyVersion)"

我希望不创建自定义任务,因为这只是一个临时解决方案,以后我将用更合适的构建系统替换它.

I'm hoping to do without creating a custom task, since this is just an interim solution, and I will replace it with a more proper build system later.

或者,我已经考虑使用 Mage命令来更新已发布的清单版本带有-Update标志的Line Tool ,但是不使用

Alternatively, I've looked at updating the published manifest version using the Mage Command Line Tool with the -Update flag, but I did not know how to retrieve the assembly version number from the project or built assembly without using PowerShell or some program that would need to be downloaded. If I could use something that comes with Visual Studio, that would work as well.

推荐答案

尝试将其添加到您的.csproj文件中.目标将从发布程序集中检索版本,并在发布之前更新ApplicationVersion:

Try adding this to your .csproj file. The target will retrieve the version from the output assembly and update the ApplicationVersion before the Publish:

<Target Name="AfterCompile">
  <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
    <Output TaskParameter="Assemblies" ItemName="fooAssemblyInfo"/>
  </GetAssemblyIdentity>
  <PropertyGroup>
    <ApplicationVersion>%(fooAssemblyInfo.Version)</ApplicationVersion>
  </PropertyGroup>
</Target>

动态获取程序集名称可能是更好的方法,但出于您的目的,应该可以解决问题.

There's probably a nicer way to dynamically get the assembly name but for your purpose it should do the trick.

为此答案使用GetAssemblyIdentity语法: https://stackoverflow.com/a/443364/266882

Credit to this answer for the GetAssemblyIdentity syntax: https://stackoverflow.com/a/443364/266882

提问者

请参阅下面的评论以获取更新.

See comment below for update.

这篇关于使用MSBuild命令行指定发布版本为项目的程序集版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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