Reputation: 2402
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 $(MSBuildProjectDirectory)
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 : )
Upvotes: 14
Views: 9761
Reputation: 9938
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)'" />
Upvotes: 21
Reputation: 11618
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).
Upvotes: 1