Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'"/> 
like image 277
Oscar Foley Avatar asked Jul 20 '10 11:07

Oscar Foley


People also ask

What is MSBuild target?

A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.

How do I set MSBuild property in Visual Studio?

MSBuild lets you set properties on the command line by using the -property (or -p) switch. These global property values override property values that are set in the project file. This includes environment properties, but does not include reserved properties, which cannot be changed.


2 Answers

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)

like image 133
Julien Hoarau Avatar answered Sep 20 '22 14:09

Julien Hoarau


MSBuild4: As Julien said, in MSBUILD 4 is possible to user Property Function.

MSBuild 3.x: In previous versions is possible if you use Tigris MsBuild Tasks

You can use task RegexMatch and use a regular expression

like image 23
Oscar Foley Avatar answered Sep 20 '22 14:09

Oscar Foley