3

Investigating a build problem that only occurs on our build server, I was surprised to see this answer point out there is both a $(ProjectDir) and a $(MSBuildProjectDir), the former sometimes not available.

What is the difference in general? Should I always be using $(MSBuildXXX) versions of properties if available? Why use $(ProjectDir) in the first place?

Contrary to advice in the other Q&A, I'm sometimes seeing $(MSBuildProjectDir) = ''.

Community
  • 1
  • 1
DuckMaestro
  • 15,232
  • 11
  • 67
  • 85

1 Answers1

5

As your linked answer says $(ProjectDir) is only available after Microsoft.Common.Targets has been imported, while $(MSBuildProjectDir) is a reserved property in MSBuild itself.

So using the $(MSBuildXXX) properties will ensure that they are always available to you without needing to import all the necessary references.

Steve
  • 9,335
  • 10
  • 49
  • 81