开发者

get parent directory in MSBuild

In NAnt i have a very simple property to get the root of my project, it looks like this.:

<property
name="project.root.folder" 
value="${directory::get-parent-directory(directory::get-parent-directory(project.local.folder))}"
/>

This takes me up to the root of my project from which I build all my paths.

In MSBuild I can use $(MS开发者_Python百科BuildProjectDirectory) to get my current directory but i would like to get the full path of the parent directory. NAnt uses directory::get-parent-directory which works a charm and i'm hoping there is something similar available in MSBuild.

I found a previous similar question (http://stackoverflow.com/questions/514264/msbuild-find-msbuildprojectdirectory-parent-directory) but I am thinking there must be something simpler available, surely!

Sam : )


I'm assuming that this is MSBuild 4.0. You can do this:

<PropertyGroup>
     <RootFolder>$([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory)))</RootFolder>
</PropertyGroup>
<Message Text="RootFolder: '$(RootFolder)'" />


The question you posted has your answer, and it looks to be a decent one. MSBuild is built around projects and not solutions, so finding something to give you a solution path requires a bit of customization. One fact to consider is that for many projects solution files aren't located at the root of the project tree (or 'cone' in MSBuild parlance).

MSBuild Reserved Properties

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜