9

Inside the .csproj there are some constants defined like this:

<DefineConstants>DEBUG;TRACE;ANDROID;GLES;OPENGL;OPENAL</DefineConstants>

Then later in the project there's an itemgroup

<ItemGroup>
<EmbeddedNativeLibrary Include="..\ThirdParty\Dependencies\openal-soft\libs\armeabi-v7a\libopenal32.so">
  <Platforms>Android,Ouya</Platforms>
  <Link>libs\armeabi-v7a\libopenal32.so</Link>
</EmbeddedNativeLibrary>
<EmbeddedNativeLibrary Include="..\ThirdParty\Dependencies\openal-soft\libs\armeabi\libopenal32.so">
  <Platforms>Android,Ouya</Platforms>
  <Link>libs\armeabi\libopenal32.so</Link>
</EmbeddedNativeLibrary>
<EmbeddedNativeLibrary Include="..\ThirdParty\Dependencies\openal-soft\libs\x86\libopenal32.so">
  <Platforms>Android,Ouya</Platforms>
  <Link>libs\x86\libopenal32.so</Link>
</EmbeddedNativeLibrary>

I want this ItemGroup to be included only when the constant OPENAL is defined, regardless of debug or release. How can I do this?

<ItemGroup Condition="XXXXXX" >

What would XXXXXX be?

1
  • 1
    Found the answer... <ItemGroup Condition="$(DefineConstants.Contains('OPENAL'))">
    – Mariano
    Aug 22, 2014 at 22:26

2 Answers 2

16

The syntax for a condition that checks if a Constant is defined is: (in this case OPENAL)

<ItemGroup Condition="$(DefineConstants.Contains('OPENAL'))">
2
  • Thanks, it solves my problem when I have two configurations. One for Debug and second for Release and can use one condition for both when a constant is defined at project's 'conditional compilation symbols' build page. Don't have to do this: Condition="'$(Configuration)' == 'TEST Debug' OR '$(Configuration)' == 'TEST Release'" but Condition="$(DefineConstants.Contains('TEST'))".
    – J Pollack
    Jan 26, 2019 at 18:34
  • The condition will also be fulfilled when checking for 'OPEN', and that's probably not expected, so you'd better check for ';OPEN;'. Oct 31, 2023 at 13:34
2

You can also use the <Choose> element to create conditional blocks in msbuild / .csproj files if you want to do more sophisticated conditional processing.

http://msdn.microsoft.com/en-us/library/ms164282.aspx

Edited: Angle brackets had disappeared.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.