在命令行建立时如何修改/替换选项集文件? [英] How to modify/replace option set file when building from command line?

查看:237
本文介绍了在命令行建立时如何修改/替换选项集文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令从批处理文件构建软件包:

I build packages from a batch file using commands like:

msbuild ..\lib\Package.dproj /target:Build /p:config=%1

包的设置取决于选项集:

The packages' settings are dependent on an option set:

<Import Project="..\optionsets\COND_Defined.optset" Condition="'$(Base)'!='' And Exists('..\optionsets\COND_Defined.optset')"/>

此选项集定义了许多我的包依赖的条件符号。该文件如下所示:

This option set defines a conditional symbol many of my packages depend on. The file looks like this:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <DCC_Define>CONDITION;$(DCC_Define)</DCC_Define>
    </PropertyGroup>
    <ProjectExtensions>
        <Borland.Personality>Delphi.Personality.12</Borland.Personality>
        <Borland.ProjectType>OptionSet</Borland.ProjectType>
        <BorlandProject>
            <Delphi.Personality/>
        </BorlandProject>
        <ProjectFileVersion>12</ProjectFileVersion>
    </ProjectExtensions>
</Project>

现在我需要两个构建:一个具有条件定义,一个没有。我的攻击向量将是选项集文件。我有一些想法要做什么:

Now I need two builds: one with the condition defined and one without. My attack vector would be the option set file. I have some ideas on what to do:


  • 编写一个修改选项集文件的程序,在批量构建之前运行此程序

  • 拖拽项目文件并修改选项集路径以包含一个环境变量,然后在不同的位置有不同的选项集

但是,在开始重塑轮子之前,我想问你将如何处理这个任务?也许已经有意味着支持这种情况(像某些命令行开关,可以在Delphi中配置的东西或批处理文件)。

But before starting to reinvent the wheel I'd like to ask how you would tackle this task? Maybe there are already means meant to support such a case (like certain command line switches, things I could configure in Delphi or batch file magic).

推荐答案

我的方法是定义多个构建配置,然后在构建时使用 / p:config = XXX 选择适当的配置。在IDE中很好地工作,因为您只需双击项目管理器中的构建配置即可将其激活。

The way I approach this is to define multiple build configurations and then select the appropriate one at build time with /p:config=XXX. The works nicely in the IDE too because you can just double click the build config in the project manager to activate it.

当我这样做时,我个人使用构建配置的继承所以我不必重复。例如,我有一个名为 Debug DCUs 的构建配置,它继承自 Debug 配置,只需更改调试DCUs 选项到 True

I personally use inheritance of build configurations when I do this so that I don't have to repeat myself. For example I have a build configuration named Debug DCUs that inherits from the Debug configuration and simply changes the Debug DCUs option to True.

为了帮助解释我的意思,这里是我项目中构建配置树的样子:

To help explain what I mean, here is what the build configuration tree looks like in my project:

通过此选项集实现调试DCU 配置: / p>

The Debug DCUs configuration is effected by means of this option set:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <DCC_DebugDCUs>true</DCC_DebugDCUs>
    </PropertyGroup>
    <ProjectExtensions>
        <Borland.Personality>Delphi.Personality.12</Borland.Personality>
        <Borland.ProjectType>OptionSet</Borland.ProjectType>
        <BorlandProject>
            <Delphi.Personality/>
        </BorlandProject>
        <ProjectFileVersion>12</ProjectFileVersion>
    </ProjectExtensions>
</Project>

现在,我相信你可以使用 / p: DCC_Define = XXX 但是,我认为使用构建配置更为清洁,以便您可以确定您获得的IDE与命令行构建的相同。

Now, I am sure that you could do this by using /p:DCC_Define=XXX but I think it is cleaner to use the build configurations so that you can be sure that what you get it the IDE is the same as what you get from the command line builds.

我不会在你的项目符号列表中推荐任何一种方法。那些方法对我来说非常脆弱。

I would not recommend either approach in your bullet point list. Those approaches look exceedingly brittle to me.

这篇关于在命令行建立时如何修改/替换选项集文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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