Christoph
Christoph

Reputation: 2004

Conditionally exclude project from Visual Studio build

I have a Visual Studio 2012 library project (VC++) that includes certain classes if a certain SDK is available. I implemented this via msbuild Conditions in a property sheet:

<Choose>
    <When Condition="Exists('C:\OFED_SDK\')">
        <PropertyGroup>
            <OfedSdkDir>C:\OFED_SDK\</OfedSdkDir>
        </PropertyGroup>
    </When>
 </Choose>
 [...]
 <ItemDefinitionGroup Condition="$(OfedSdkDir) != ''">
     <ClCompile>
          <AdditionalIncludeDirectories>$(OfedSdkDir)Inc\; %(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
          <PreprocessorDefinitions>HAVE_OFED_SDK; %(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
 [...]

Certain functionality is only available if HAVE_OFED_SDK is defined. This works perfectly.

The solution furthermore contains several projects for testing the library project. The test for the classes compiled conditionally are in a separate project.

My question is: Can I build this project depending on whether the above-mentioned condition (Condition="$(OfedSdkDir) != '' is true? If so, how would I do that? I need a solution that also works when building from VS.

Edit: I am aware of the solution Martin proposed, but I am looking for a solution that is working programmatically, ie which does not allow the user to enable the "wrong" configuration via the GUI.

Edit: I found that I can add (Condition="$(OfedSdkDir) != '' to the ClCompile of the source file which almost achieves what I want, but still runs the build process for the project.

Upvotes: 0

Views: 1525

Answers (1)

Martin Costello
Martin Costello

Reputation: 10843

Just setup a different solution configuration that doesn't attempt to build the relevant projects that you want to exclude.

For example, call it "Release-No-OFED" and un-tick those projects from being compiled in that configuration.

Upvotes: 1

Related Questions