Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

test if an MSBuild property is defined?

Tags:

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> 
like image 461
Stato Machino Avatar asked Feb 10 '11 00:02

Stato Machino


People also ask

What is MSBuild property?

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.

Which tag is used to specify the path of project in MSBuild?

For example, bin\Debug. Specifies the path to the output directory, relative to the project directory, for example, bin\Debug.

What is MSBuildProjectDirectory?

MSBuildProjectDirectory is the property that will give you the full path to the project file which was invoked on the command line.

Where is MSBuildExtensionsPath?

This file is installed by Visual Studio to the standard $(MSBuildExtensionsPath) location (C:\Program Files\MSBuild).


1 Answers

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?

like image 117
Sergio Rykov Avatar answered Oct 20 '22 16:10

Sergio Rykov