获取 MSBuildProjectDirectory 的父目录

dem*_*emo 1 directory msbuild 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>
Run Code Online (Sandbox Code Playgroud)

效果不佳,因为我需要进入父目录才能找到 MyApp.Services.Infrastructure.sln

结构 :

SolutionFolder

 -- MsBuildsFolder

 -- ProjectFile
Run Code Online (Sandbox Code Playgroud)

这是非常相似的问题,但没有解决我的问题

Chr*_*n.K 5

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

  <PropertyGroup>
    <RootPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), MyApp.Services.Infrastructure.sln))</RootPath>
  </PropertyGroup> 
Run Code Online (Sandbox Code Playgroud)