Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get parent directory in MSBuild

Tags:

.net

msbuild

nant

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 : )

like image 872
samaspin Avatar asked Jun 07 '11 21:06

samaspin


2 Answers

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)'" />
like image 111
Brian Kretzler Avatar answered Sep 22 '22 15:09

Brian Kretzler


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

like image 40
Ritch Melton Avatar answered Sep 21 '22 15:09

Ritch Melton