TheDude
TheDude

Reputation: 3105

How to specify File Version when building EXE using MSBuild?

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?

Upvotes: 1

Views: 5949

Answers (3)

Sean Clifford
Sean Clifford

Reputation: 176

Using VerInfo_Keys as an MSBuild property has worked for me. The rest of the assembly properties you want also need to be provided at the same time however.

msbuild.exe "D:\MyProject\MyFile.dproj" /p:Config=Release /p:VerInfo_Keys="FileVersion=1.2.3.4;ProductVersion=1.2.3.4;LegalCopyright=Copyright © My Company;ProductName=My Product;CompanyName=My Company" /t:Clean;Build

Upvotes: 2

Alexey Shumkin
Alexey Shumkin

Reputation: 419

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

Upvotes: 0

DaveE
DaveE

Reputation: 3637

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.

Upvotes: 3

Related Questions