Search code examples
msbuildnugetmsbuild-task

MSBuild, how can I get the second parent


MSBuild (targets file), how can I get the second parent of an address like this?

  <PropertyGroup>
    <LibFolder>$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)))</LibFolder>
  </PropertyGroup>

This is for one level parent, how can I get the 2nd level? (Parent of the parent)


Solution

  • Simply call the function again, on the previous result:

      <PropertyGroup>
        <LibFolder>$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)))</LibFolder>
        <LibFolder>$([System.IO.Directory]::GetParent($(LibFolder)))</LibFolder>
      </PropertyGroup>