Why does this MSBuild script not set the property as I expect?

I am trying to set the default value for the MSBuild property. Let's say I start with this:

<Choose>
    <When Condition="..something..">
        <PropertyGroup>
            ...
            <MySetting>true</MySetting>
        <PropertyGroup>
    </When>
    ...
</Choose>

If the condition is not true, then the value will be indicated on MySetting. '' So this should not be false?

<PropertyGroup>
    <MySetting Condition="'$(MySetting)'==''">false</MySetting>
</PropertyGroup>

Later, I would like to use MySetting in a conditional expression without checking for == 'true', for example:

<PropertyGroup Condition="$(MySetting)">
    ...
</PropertyGroup>

But when I load this project in Visual Studio, it complains that the specified condition "$ (MySetting)" is evaluated as "" instead of a boolean.

Thus, it seems that either my condition, which checks `` to set the false property, is incorrect. What am I doing wrong?

+5
source share
2 answers

MSBuild , '' false... 'false' , script:

<PropertyGroup>
    <MySetting>false</MySetting>
</PropertyGroup>

true, , :

MSBuild.exe MyMSBuildFile.csproj /p:MySetting=true
+6

, Chose - :

<PropertyGroup>
    <MySetting Condition=" '$(MySetting)'=='' ">true</MySetting>
</PropertyGroup>

'', , bool. :

<PropertyGroup Condition=" '$(MySetting)'=='true' ">
</PropertyGroup>
+3

All Articles