Delphi 预构建事件在编译前未执行 [英] Delphi pre-build event not executing BEFORE compile

查看:27
本文介绍了Delphi 预构建事件在编译前未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正忙于自动化我们的构建以包含 svn 修订号.我们使用的是 Delphi 2010.我添加了一个调用批处理文件的预构建事件,该文件将 svn 修订号(从 .svn 目录中的条目文件中读取)和指定的版本号注入 aVersionInfo.rc 中我的项目.预构建事件如下所示:

I'm busy automating our builds to include the svn revision number. We're using Delphi 2010. I added a pre-build event calling a batch file that injects the the svn revision number (read from the entries file in the .svn directory) and a specified version number into aVersionInfo.rc that is compiled with my project. The pre-build event looks like this:

call SetVersionInfo.bat 6 5 4

...和批处理文件(希望有人觉得这有用)...

...and the batch file (hope someone finds this useful)...

@ECHO OFF
SETLOCAL
setLocal EnableDelayedExpansion

SET _myVar=0
FOR /F %%G in (.svnentries.) DO (
IF !_myVar! LSS 3 SET /A _myVar+=1 & SET _svn_dir_rev=%%G
)

ECHO 1 VERSIONINFO > aVersionInfo.rc
ECHO. FILEVERSION %1,%2,%3,%_svn_dir_rev%   >> aVersionInfo.rc
ECHO. PRODUCTVERSION 1   >> aVersionInfo.rc
ECHO. FILEOS VOS__WINDOWS32   >> aVersionInfo.rc
ECHO. FILETYPE VFT_APP   >> aVersionInfo.rc
ECHO. BEGIN   >> aVersionInfo.rc
ECHO.   BLOCK "StringFileInfo"   >> aVersionInfo.rc
ECHO.   BEGIN   >> aVersionInfo.rc
ECHO.     BLOCK "080904b0"   >> aVersionInfo.rc
ECHO.     BEGIN   >> aVersionInfo.rc
ECHO.       VALUE "CompanyName","COMPANY00"   >> aVersionInfo.rc
ECHO.       VALUE "FileDescription","APP00"   >> aVersionInfo.rc
ECHO.       VALUE "FileVersion","%1.%2.%3.%_svn_dir_rev%00"   >> aVersionInfo.rc
ECHO.       VALUE "InternalName","APP00"   >> aVersionInfo.rc
ECHO.       VALUE "LegalCopyright","Copyright APP00"   >> aVersionInfo.rc
ECHO.       VALUE "LegalTrademarks","APP00"   >> aVersionInfo.rc
ECHO.       VALUE "OriginalFilename","APP.exe00"   >> aVersionInfo.rc
ECHO.       VALUE "ProductName","APP00"   >> aVersionInfo.rc
ECHO.       VALUE "ProductVersion,"100"   >> aVersionInfo.rc
ECHO.       VALUE "Comments","Compiled on %date% by %username%00"   >> aVersionInfo.rc
ECHO.     END   >> aVersionInfo.rc
ECHO.   END   >> aVersionInfo.rc
ECHO.   BLOCK "VarFileInfo"   >> aVersionInfo.rc
ECHO.   BEGIN   >> aVersionInfo.rc
ECHO.     VALUE "Translation", 0x0809 1200   >> aVersionInfo.rc
ECHO.   END   >> aVersionInfo.rc
ECHO. END   >> aVersionInfo.rc
ENDLOCAL

批处理文件确实作为编译的一部分执行,更新了 aVersionInfo.rc,重新编译了 aVersionInfo.res,但由于某种原因,新的 res 文件未用于编译 exe.但是,它会在干净构建期间或我第二次编译时更新.似乎在调用预"构建事件之前检查对 rc 文件的更改.这实际上使它成为一个中期构建事件.或者我错过了什么?

The batch file does execute as part of a compile, aVersionInfo.rc is updated, aVersionInfo.res is recompiled, but for some reason the new res file is not used to compile the exe. It is, however, updated during a clean build or if I compile a second time. It seems the check for changes to the rc files takes place before the "pre"-build events are called. Which actually makes it a mid-build event. Or am I missing something?

我确实尝试删除 aVersionInfo.res 文件作为另一个预构建事件,但随后编译器抱怨此文件丢失.难道是

I did try deleting the aVersionInfo.res file as another pre-build event, but then the compiler complains that this file is missing. Could it be that the

{$R 'aVersionInfo.res' 'aVersionInfo.rc'}

线在错误的地方?

推荐答案

尝试使用

{$R aVersionInfo.res}

并从您的批处理文件中手动调用 brcc32 aVersionInfo.rc(在您完成创建 .rc 文件之后).这样你的 .res 文件应该被排除在正常的 IDE 构建之外.

and calling brcc32 aVersionInfo.rc manually from your batch file (after you're done with creating the .rc file). That way your .res file should be excluded from the normal IDE build.

这篇关于Delphi 预构建事件在编译前未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆