computational_linguist
computational_linguist

Reputation: 113

MSBuild builds target even though condition is false

I have an MSBuild project file that builds a target even though its Condition is false

<PropertyGroup>
  <BuildDir>$(ProjectDir)build\</BuildDir>
</PropertyGroup>
<Target Name="MakeBuildDir" Condition="!Exists('($BuildDir)')">
  <MakeDir Directories="$(BuildDir)" />
</Target>

BuildDir does exist, and it runs this task anyway.

From the log file:

15:32:17.162     1>Target "MakeBuildDir: (TargetId:3)" in project "foo.vcxproj" (target "bar" depends on it):
                   Using "MakeDir" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
                   Task "MakeDir" (TaskId:4)
                   Done executing task "MakeDir". (TaskId:4)
15:32:17.162     1>Done building target "MakeBuildDir" in project "KB.vcxproj".: (TargetId:3)
15:32:17.162     1>Target "bar: (TargetId:4)" in project "foo.vcxproj" (target "Build" depends on it):
                   Skipping target "bar" because all output files are up-to-date with respect to the input files.

This isn't a crucial problem for me, but if I do two immediate builds on my solution, I want the second one to show me that all 11 of my projects are up-to-date. Now it takes a few seconds then says 2 succeeded and 9 are up-to-date.

Upvotes: 1

Views: 530

Answers (1)

computational_linguist
computational_linguist

Reputation: 113

Sorry. It works if I change the target line to

<Target Name="MakeBuildDir" Condition="!Exists('$(BuildDir)')">

(though it still shows as succeeding, not up-to-date....)

Upvotes: 2

Related Questions