是否可以访问(在构建文件中)调用MSBuild.exe的目录?
我只能获得构建文件本身的路径。我想要调用MSBuild的目录。
预期
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>
为什么
我想知道是否可以替换
中的绝对路径D:\workdir> msbuild foo\foo.proj /p:Parameter=d:\workdir\Projects\bar\
带有相对路径
D:\workdir> msbuild foo\foo.proj /p:Parameter=Projects\bar\
答案 0 :(得分:3)
请参阅MSBuild Reserved and Well-Known Properties
看起来MSBuildStartupDirectory
会对您有所帮助:
TestBuild.vcxproj摘录
<Target Name="BeforeBuild">
<Message Text="MSBuild was called from: $(MSBuildStartupDirectory)" />
</Target>
<强>构建强>
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