How to specify File Version when building EXE using MSBuild?

为君一笑 提交于 2021-02-16 15:15:08

问题


I'm trying to compile an EXE using MSBuild / Delphi 2010, I tried this:

MSBuild.exe /t:Clean;Build /p:config=Release;ExtraDefines="CodeTest" /property:FileVersion=1.0.0.15 "D:\MyProject\MyFile.dproj"

File is built but version isn't set

What's wrong anyway?


回答1:


Your property "FileVersion" is available inside the MSBuild session, but unless you have a Task or Target that uses it somehow, it's not being used for anything. You'll either need to (as DHeffernan says) create a version resource that your code uses or use a post-compile tool to apply the version info to your exe or dll.

This StackOverflow article lists a number of tools to do the post-compile thing.




回答2:


The main problem here is that FileVersion "attribute" is a part of CSV-list of VerInfo_Keys property but not a property itself.

So, the solution which is seen to me is:

  1. Take VersInfo_Keys property (CSV-list)
  2. Split it to Key=Value pairs
  3. Change value of FileVersion=... pair
  4. Join list back to CSV-list.

I've implemented this with an MSBuild Inline Task (N.B.: .NET Framework 4.0 and above must be used):

  1. Put the gist (noticed above) to a lib\MSBuildTasks\Delphi.VersionInfo.targets file (git submodule in my case)

  2. Add to a Delphi project file (say delphi-project.dproj):

    <Import Project="lib\MSBuildTasks\Delphi.VersionInfo.targets" Condition="$(FileVersion)!='' and Exists('lib\MSBuildTasks\Delphi.VersionInfo.targets')"/>

    condition "FileVersion is set" is to avoid failure in Delphi as the latter uses .NET 3.5 which does not support inline tasks (so, FileVersion is only set when run with MSBuild).

  3. run

    msbuild delphi-project.dproj /t:build /p:FileVersion=A.B.C.D

The same I use for Android apps (with Delphi XE7/10 Seattle). Just VersionName and VersionCode "properties" are used rather than FileVersion (N.B. Import's condition is changed appropriately).

msbuild delphi-project.dproj /t:build /p:VersionName=A.B.C.D



来源:https://stackoverflow.com/questions/10251061/how-to-specify-file-version-when-building-exe-using-msbuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!