1

I have solution with projects. Also I have in solution directory folder with msbuild files.

In msbuild file I have next code :

<PropertyGroup Label="Build Directories">
   <RootPath>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)'))</RootPath>
</PropertyGroup>

<ItemGroup>
   <MSBuildProjectInfrastructure Include="$(RootPath)MyApp.Services.Infrastructure.sln">
   <AdditionalProperties>Configuration=$(Configuration);Platform=$(Platform);</AdditionalProperties>
   </MSBuildProjectInfrastructure>
 </ItemGroup>

Which works badly, as I need to go in parent directory to find MyApp.Services.Infrastructure.sln

Structure :

SolutionFolder

 -- MsBuildsFolder

 -- ProjectFile

Here is quite similar question, but doesn't resolve my issue

demo
  • 6,038
  • 19
  • 75
  • 149

1 Answers1

5

To get the parent folder, you can let MSBuild determine the location of known file in that folder by means of the built in property function GetDirectoryNameOfFileAbove:

  <PropertyGroup>
    <RootPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), MyApp.Services.Infrastructure.sln))</RootPath>
  </PropertyGroup> 
0xced
  • 25,219
  • 10
  • 103
  • 255
Christian.K
  • 47,778
  • 10
  • 99
  • 143