Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Conditional Symbol inside .csproj

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?

like image 293
Mariano Avatar asked Aug 22 '14 22:08

Mariano


2 Answers

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

<ItemGroup Condition="$(DefineConstants.Contains('OPENAL'))">
like image 149
Mariano Avatar answered Sep 20 '22 23:09

Mariano


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.

like image 21
Jorgen Thelin Avatar answered Sep 22 '22 23:09

Jorgen Thelin