簡體   English   中英

使用 MSBuild 構建 EXE 時如何指定文件版本?

[英]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列表的一部分,但不是屬性本身。

所以,我看到的解決方案是:

  1. 使用VersInfo_Keys屬性(CSV列表)
  2. 將其拆分為Key = Value對
  3. 更改FileVersion = ...對的值
  4. 將列表加入CSV列表。

我已經使用MSBuild內聯任務 實現了這個(NB:必須使用.NET Framework 4.0及更高版本):

  1. 把要點(上面注意到)放到lib\\MSBuildTasks\\Delphi.VersionInfo.targets文件(在我的例子中為git子模塊)
  2. 添加到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一起運行時設置)。

  3. msbuild delphi-project.dproj /t:build /p:FileVersion=ABCD

我用於Android應用程序(使用Delphi XE7 / 10 Seattle)。 僅使用VersionNameVersionCode “屬性”而不是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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM