问题
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:
- Take
VersInfo_Keys
property (CSV-list) - Split it to Key=Value pairs
- Change value of FileVersion=... pair
- 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):
Put the gist (noticed above) to a
lib\MSBuildTasks\Delphi.VersionInfo.targets
file (git submodule in my case)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).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