Reputation: 20843
Is it possible to access (in a build file) the directory from which MSBuild.exe was called?
I have only been able to get the path of the build file itself. I want the directory from which MSBuild was called instead.
Expected
D:\> msbuild foo\foo.proj
...
MSBuild was called from: D:\>
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="BeforeBuild">
<Message Text="MSBuild was called from: ???" />
</Target>
</Project>
Why
I was wondering if one could replace the absolute path in
D:\workdir> msbuild foo\foo.proj /p:Parameter=d:\workdir\Projects\bar\
with a relative path
D:\workdir> msbuild foo\foo.proj /p:Parameter=Projects\bar\
Upvotes: 2
Views: 192
Reputation: 1281
See MSBuild Reserved and Well-Known Properties
It looks like MSBuildStartupDirectory
will help you:
TestBuild.vcxproj snippet
<Target Name="BeforeBuild">
<Message Text="MSBuild was called from: $(MSBuildStartupDirectory)" />
</Target>
Build
d:\Data\Visual Studio 2013\Projects>msbuild /m .\TestMsBuild\TestMsBuild\TestMsBuild.vcxproj /verbosity:detailed /t:BeforeBuild
Task "Message"
MSBuild was called from: d:\Data\Visual Studio 2013\Projects
Upvotes: 3