How to modify/replace option set file when building from command line?

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:

  • write a program which modifies the option set file, run this before batch build
  • fiddle with the project files and modify the option set path to contain an environment variable, then have different option sets in different locations

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).

Answers


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.

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:

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>

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.


Need Your Help

Javascript “this” in a jquery event

javascript jquery function this

How can I call functionOne correctly within the Jquery change function? "this" is no longer referencing the object.

How to create a proper Makefile and does the order of dependecies matter?

c makefile

I have 5 files that I must use makefile to create one file.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.