在 MSBuild 中将程序集版本号指定为命令行参数 [英] Specify assembly version number as a command line argument in MSBuild

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

问题描述

我希望能够将构建期间生成的所有程序集的版本号指定为 MSBuild 命令参数,如下所示:

I would like to be able to specify the version number for all assemblies to be generated during a build as a MSBuild command argument like this:

MSBuild.exe /p:version=5.4.3.0 

我已经查看了 AssemblyInfoTask,但在我看来,在这种情况下它并不是一个好的解决方案.

I have looked over AssemblyInfoTask but it does not seem to me like a good solution in this case.

推荐答案

我一直使用您在评论中描述的 AssemblyInfo 任务.

I use the AssemblyInfo task as you describe in your comment all the time.

  <!-- update standard assembly attribute in all projects -->
  <Target Name="BeforeBuild" >
    <Message Text="Updating AssemblyInfo to Version $(VersionNumber)"></Message>
    <Message Text="Writing to AssemblyInfo files in $(SolutionRoot)"></Message>
    <AssemblyInfo AssemblyInfoFiles="@(AssemblyInfoFiles)" 
                  AssemblyCopyright="$(AssemblyCopyright)" 
                  AssemblyVersion="$(VersionNumber)"
                  AssemblyFileVersion="$(VersionNumber)"
                  >
    </AssemblyInfo>
  </Target>

VersionNumber 值完全按照您的描述从 MSBuild 项目文件外部传递:

The VersionNumber value is passed from outside the MSBuild project file exactly as you describe:

  MSBuild <project_file> /p:VersionNumber=<value>;...

我们使用 BeforeBuild 目标来确保 AssemblyInfo.cs 文件在构建开始之前得到处理.这不是你想要的吗?

We use the BeforeBuild target to ensure the AssemblyInfo.cs files all get worked on before the build starts. Is this not what you want?

这篇关于在 MSBuild 中将程序集版本号指定为命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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