获取MSBuildProjectDirectory的父目录

时间:2017-08-08 11:30:46

标签: msbuild directory parent targets

我有项目解决方案。我也在解决方案目录文件夹中有msbuild文件。

在msbuild文件中,我有下一个代码:

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

这很糟糕,因为我需要进入父目录才能找到MyApp.Services.Infrastructure.sln

结构:

SolutionFolder

 -- MsBuildsFolder

 -- ProjectFile

以下是quite similar question,但未解决我的问题

1 个答案:

答案 0 :(得分:3)

要获取父文件夹,您可以让MSBuild通过内置属性函数GetDirectoryNameOfFileAbove确定该文件夹中已知文件的位置:

  <PropertyGroup>
    <RootPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), MyApp.Services.Infrastructure.sln))</RootPath>
  </PropertyGroup> 
相关问题