[# MSBUILD] HowTo: Set a value in a property according to a condition (XXI)

image47dd1de4

Hi,

wherever I have to process a condition to set the value of a property, I conclude by making a few very rare lines ofMSBuild. I’m going to sign this post so that within 2 hours I remember as I resolve it in a simple way.

In the following example, we see that Target1 shows the value of the property $(Log). The value of the same is processed between 4 and 8, lines and depending on whether there is or not a file log, the property can take the values:

  • There is no Log
  • c:\file1.log
  • c:\file2.log

 

   1: <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"

2: InitialTargets=”Target1″>

3: <PropertyGroup>

4: <Log1>c:\file1.log</Log1>

5: <Log2>c:\file2.log</Log2>

6: <Log>No hay Log</Log>

7: <Log Condition=”Exists(‘$(Log1)’)”>$(Log1)</Log>

8: <Log Condition=”Exists(‘$(Log2)’)”>$(Log2)</Log>

9: </PropertyGroup>

10: <Target Name=”Target1″>

11: <Message Text=”Start Demo” />

12: <Message Text=”Log: $(Log)” />

13: </Target>

14: </Project>

 

 

Simple and easy Open-mouthed smile

 

Greetings @ Here

The Bruno

   

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: