31

In MsBuild, is it possible to create an MSBuild condition (or another situation) that will evaluate whether a Property is 'defined' (presuming that this is previous to assigning the property a value somewhere)?

The following seems a little too clumsy to be reliable:

<PropertyGroup Label="Undefined State">
     <Defined></Defined>
</PropertyGroup>

<Choose>
   <When Condition="('$(Defined)' == '' OR '$(Defined)' != '')">
        <Message Text="Defined is probably/likely/assuredly defined"/>
    </When>
    <Otherwise>
       <Message Text="Defined is reportedly/maybe/possibly not defined"/>
    </Otherwise>
<Choose>
Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
Stato Machino
  • 1,120
  • 3
  • 13
  • 22

1 Answers1

55

There exists common method for overriding properties.

Sample from C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets

   <PropertyGroup>
       <TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">.NETFramework</TargetFrameworkIdentifier>
       <TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' ">v4.0</TargetFrameworkVersion>
   </PropertyGroup>

If you will try to get value from $(NeverDefinedProperty) you just get an empty string. Can you describe the problem you want to solve?

Sergio Rykov
  • 4,176
  • 25
  • 23