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.
MSBuildProjectDirectoryis 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.projimportsshared.targetsand this is the one passed to msbuild.exe then the value forMSBuildProjectDirectorywill 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 forOutputPathand the shared fileMicrosoft.Common.targetsuses 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.