[英]How to specify File Version when building EXE using MSBuild?
我正在嘗試使用 MSBuild / Delphi 2010 編譯 EXE,我試過這個:
MSBuild.exe /t:Clean;Build /p:config=Release;ExtraDefines="CodeTest" /property:FileVersion=1.0.0.15 "D:\MyProject\MyFile.dproj"
文件已構建但未設置版本
到底怎么了?
您的屬性“FileVersion”在MSBuild會話中可用,但除非您有一個以某種方式使用它的任務或目標,否則它不會用於任何事情。 您需要(如DHeffernan所說)創建代碼使用的版本資源,或者使用后編譯工具將版本信息應用於您的exe或dll。
這篇StackOverflow文章列出了許多用於進行后編譯的工具。
這里的主要問題是FileVersion
“attribute”是VerInfo_Keys
屬性的CSV列表的一部分,但不是屬性本身。
所以,我看到的解決方案是:
VersInfo_Keys
屬性(CSV列表) 我已經使用MSBuild內聯任務 實現了這個(NB:必須使用.NET Framework 4.0及更高版本):
lib\\MSBuildTasks\\Delphi.VersionInfo.targets
文件(在我的例子中為git子模塊) 添加到Delphi項目文件(例如delphi-project.dproj
):
<Import Project="lib\\MSBuildTasks\\Delphi.VersionInfo.targets" Condition="$(FileVersion)!='' and Exists('lib\\MSBuildTasks\\Delphi.VersionInfo.targets')"/>
條件“FileVersion已設置”是為了避免Delphi中的失敗,因為后者使用的.NET 3.5不支持內聯任務(因此,FileVersion僅在與MSBuild一起運行時設置)。
跑
msbuild delphi-project.dproj /t:build /p:FileVersion=ABCD
我用於Android應用程序(使用Delphi XE7 / 10 Seattle)。 僅使用VersionName
和VersionCode
“屬性”而不是FileVersion
(NB Import
的條件已適當更改)。
msbuild delphi-project.dproj /t:build /p:VersionName=ABCD
使用VerInfo_Keys
作為 MSBuild 屬性對我有用。 但是,您想要的組件屬性的 rest 也需要同時提供。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.