简体   繁体   English

MSBuild和多个Delphi版本

[英]MSBuild and multiple Delphi versions

I have a project for which I need to build two executables: one under Delphi XE2 and one under XE3. 我有一个项目,我需要构建两个可执行文件:一个在Delphi XE2下,一个在XE3下。 I have a build script which builds each version (ie one script for XE2 and one for XE3). 我有一个构建脚本来构建每个版本(即XE2的一个脚本和XE3的一个脚本)。

If I run the build script for the last version of the IDE I ran, all works well (ie run Delphi XE2, build app, run XE2 build script). 如果我运行我运行的IDE的最后一个版本的构建脚本,一切运行良好(即运行Delphi XE2,构建应用程序,运行XE2构建脚本)。

However if I run the build script having just run a different version of the IDE I get an AV as soon as my app starts (Ie run Delphi XE2, built app, run XE3 build script). 但是,如果我运行构建脚本只运行不同版本的IDE,我会在应用程序启动后立即获得AV(即运行Delphi XE2,构建应用程序,运行XE3构建脚本)。

It looks as though something about the build script is being cached/modified by the IDE and I need to restore the appropriate data for the version I want to build with. 看起来好像IDE正在缓存/修改构建脚本,我需要恢复我想要构建的版本的相应数据。 I've tried this with the .dproj, but no luck. 我用.dproj尝试过这个,但没有运气。

Or could it be loading form resources - both editions show errors due to non-existent properties at start up if the IDE. 或者它可能是加载表单资源 - 两个版本都显示错误,因为如果IDE启动时不存在属性。 If so, is there an easy way around this without having maintain multiple versions of all the .fmx files? 如果是这样,有没有一个简单的方法来保持所有.fmx文件的多个版本?

Here's a sample build script: 这是一个示例构建脚本:

set path=%path%;c:\Windows\Microsoft.NET\Framework\v3.5
set path=%path%;c:\Program Files (x86)\Embarcadero\RAD Studio\10.0
set path=%path%;c:\Documents and Settings\All Users\Documents\RAD Studio\10.0
set BDS=c:\Program Files (x86)\Embarcadero\RAD Studio\10.0
set FrameworkDir=c:\Windows\Microsoft.NET\Framework\
set FrameworkVersion=v3.5

set failed=false
cd \myprogs\monkeystyler
msbuild monkeystyler.dproj /t:build /p:config=full||set failed=true
cd build
if not %failed%==true goto Done

echo ****FAILED TO BULD MONKEYSTYLER
****
Pause
exit

:done

Let's take a look at this line in your XE3 script: 我们来看看XE3脚本中的这一行:

set path=%path%;c:\Program Files (x86)\Embarcadero\RAD Studio\10.0

My guess is that you follow that up in the XE2 script with: 我的猜测是你在XE2脚本中遵循以下内容:

set path=%path%;c:\Program Files (x86)\Embarcadero\RAD Studio\9.0

At which point your path variable looks like this: 此时您的路径变量如下所示:

set path=%path%;c:\Program Files (x86)\Embarcadero\RAD Studio\10.0;c:\Program Files (x86)\Embarcadero\RAD Studio\9.0

And so the second script fails because the paths from the first script appear earlier. 因此第二个脚本失败,因为第一个脚本的路径出现得更早。

The elegant way to fix this is to use setlocal and endlocal in your scripts to isolate them from each other. 解决此问题的优雅方法是在脚本中使用setlocalendlocal将它们彼此隔离。

setlocal
set path=%path%;c:\Windows\Microsoft.NET\Framework\v3.5
set path=%path%;c:\Program Files (x86)\Embarcadero\RAD Studio\10.0
.....
endlocal

The hacky way to fix it is to set the path like this: 修复它的hacky方法是设置这样的路径:

set path=c:\Program Files (x86)\Embarcadero\RAD Studio\10.0;%path%

Please use the elegant approach! 请使用优雅的方法!


What's more you should use pushd and popd to isolate directory changes to each script. 你还应该使用pushd和popd来隔离每个脚本的目录更改。

If this doesn't solve everything, do give more information. 如果这不能解决所有问题,请提供更多信息。 For a start, error messages are very useful. 首先,错误消息非常有用。

The last IDE that you run will update the EnvOption.proj in your <user>\\AppData\\Roaming\\Embarcadero\\BDS\\<version> folder. 您运行的最后一个IDE将更新<user>\\AppData\\Roaming\\Embarcadero\\BDS\\<version>文件夹中的EnvOption.proj。

This contains all your search paths, among other things. 这包含所有搜索路径等。

This file is indirectly included in your project. 此文件间接包含在您的项目中。 So if you run say XE2's IDE then compile your XE3 app, you will get the wrong paths. 因此,如果您运行说XE2's IDE然后编译您的XE3应用程序,您将得到错误的路径。

You will probably want to disable that and explicitly specify your search paths in each project's dproj file. 您可能希望禁用它并在每个项目的dproj文件中明确指定搜索路径。

eg msbuild myproj.proj /p:ImportEnvOptions=false

This is my best guess. 这是我最好的猜测。 Sorry if it's 5 years too late. 对不起,如果它已经晚了5年。 I have just struggled with similar issues! 我刚刚遇到类似的问题!

All the best 祝一切顺利

Steve 史蒂夫

I went back to my suspicion that it was the form file resources. 我又回到了怀疑它是表单文件资源。

My theory was that the with the form files saved by the 'wrong' version of the IDE, when a project built with a different version tried to load them I was getting access violations due to the app trying to load data for properties which where not available in that edition. 我的理论是,使用IDE的“错误”版本保存的表单文件,当使用不同版本构建的项目尝试加载它时,由于应用程序尝试加载属性而不是该版本有售。

To test this I got compiled the project successfully in one version of the IDE (XE3 in this case), did my automated build and tested that the app ran (it did). 为了测试这个,我在IDE的一个版本(在这种情况下是XE3)中成功编译了项目,进行了自动构建并测试了应用程序运行(确实如此)。

I then loaded a .fmx file for the project and added a non-existent property to the form. 然后我为项目加载了一个.fmx文件,并向表单添加了一个不存在的属性。

Build and the app fails same as before. 构建和应用程序失败与以前相同。

Remove the added property and build now succeeds. 删除添加的属性,现在构建成功。

All (!) I need to do now is write some code to parse the form files and remove any non-existent properties for the version I'm building. 我现在需要做的所有(!)是编写一些代码来解析表单文件并删除我正在构建的版本的任何不存在的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM