Is there any MSbuild task to check if a string contains another string (similar to string.contains)

Oscar Foley picture Oscar Foley · Jul 20, 2010 · Viewed 23.6k times · Source

I have this Msbuild code:

<Import Project="A.proj" Condition="$(BuildDefinition) =='Dist Staging to Dev' Or $(BuildDefinition) =='Dist Staging to Dev(Services Only)'"/>

But I was wondering if is there anything similar to check if an string contains some text to get something similar to:

<Import Project="A.proj" Condition="$(BuildDefinition) CONTAINS 'Dist Staging to Dev'"/>

Answer

Julien Hoarau picture Julien Hoarau · Jul 20, 2010

If you use MSBuild 4, you could use Property function

<Import Project="A.proj" 
        Condition="$(BuildDefinition.Contains('Dist Staging to Dev'))"/>

(More info on Property function)