获取 MSBuildProjectDirectory 的父目录

问题描述 投票:0回答:1

我有项目的解决方案。我在解决方案目录文件夹中也有 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

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

msbuild directory parent targets
1个回答
5
投票

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

  <PropertyGroup>
    <RootPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), MyApp.Services.Infrastructure.sln))</RootPath>
  </PropertyGroup> 
© www.soinside.com 2019 - 2024. All rights reserved.