tags:

views:

744

answers:

1

Hi,

MSBuild 3.5

I have the following project structure:

trunk/MainSolution.sln
trunk/Build/MyBuild.Proj
trunk/Library/...
trunk/etc...

So far, I've been using the following property to find out the project root folder:

<RootFolder>$(MSBuildProjectDirectory)\..\</RootFolder>

Everything was working great, until I tried using a copy task that relied on this path. It is not resolving correctly. I basically end up getting something like this which is not valid:

C:\Projects\MyProject\Trunk\Build\..\CodeAnalysis\myfile.xml

So basically, I need to get the full path for (MSBuildProjectDirectory)'s Parent. Any help is appreciated.

Thx.

+1  A: 

Item metadata is your friend!

<Target Name="GetMSBuildProjectParentDirectory">
  <!-- First you create the MSBuildProject Parent directory Item -->
  <CreateItem Include="$(MSBuildProjectDirectory)\..\">
    <Output ItemName="MSBuildProjectParentDirectory" TaskParameter="Include"/>
  </CreateItem>

  <!-- You can now retrieve its fullpath using Fullpath metadata -->
  <Message Text="%(MSBuildParentDirectory.Fullpath)"/>

  <!-- Create a property based on parent fullpath-->
  <CreateProperty Value="%(MSBuildParentDirectory.Fullpath)">
    <Output PropertyName="CodeFolder" TaskParameter="Value"/>
  </CreateProperty>
</Target>
madgnome
That looks great! Do you know how I can use this to create a variable with the path?e.g. <CodeFolder>%(MSBuildParentDirectory.Fullpath)</CodeFolder>But obviously that doesn't work...
B Z
Properties are evaluated before target execution, you must use the CreateProperty task (see my edit)
madgnome
Ok, so you are saying I have to use the create property task? The reason I ask is because I currently have about 5 properties that need this path.e.g. CodeFolder, DBFolder, DeployFolder, etc...
B Z
If you absolutely need 5 properties, yes that's what I'm saying.
madgnome