In my MSBuild script I need to pass the full directory as a parameter. How can I get it?
Example: I am running the script from C:\dev, and I want a relative path, temp, so I am after C:\dev\temp.
Note: I don't know from which folder the script will be run.
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:
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 also use these properties for this type of value.
See http://sedodream.com/2010/03/11/MSBuild40ReservedProperties.aspx.