2017-08-08 71 views
1

我有項目解決方案。此外,我在解決方案目錄文件夾與MSBuild文件。獲取MSBuildProjectDirectory的父目錄

在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,但不能解決我的問題

回答

3

獲取父文件夾,你可以讓通過的MSBuild的方式確定該文件夾中已知文件的位置,內置的屬性功能GetDirectoryNameOfFileAbove

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