Igor is pretty close. MSBuildProjectDirectory is the property that will give you the full path to the project file which was invoked on the command line. So if you have the following scripts:
- C:\temp\MyProj.proj
- C:\shared\shared.targets
And MyProj.proj imports shared.targets and this is the one passed to msbuild.exe then the value for MSBuildProjectDirectory will always be C:\temp even if you are referencing that inside of shared.targets. If your shared.targets requires path knowledge then those should be declared in known properties. For example C# project files define the value for OutputPath and the shared file Microsoft.Common.targets uses that property.
Edit: MSBuild 4
If you are using MSBuild 4 you can now use the properties for this type of value.
- MSBuildThisFile
- MSBuildThisFileDirectory
- MSBuildThisFileDirectoryNoRoot
- MSBuildThisFileExtension
- MSBuildThisFileFullPath
- MSBuildThisFileName
See http://sedodream.com/2010/03/11/MSBuild40ReservedProperties.aspx.