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

查看:271
本文介绍了在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>

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

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天全站免登陆