Find MSBuildProjectDirectory Parent Directory

与世无争的帅哥 提交于 2020-01-01 08:34:25

问题


MSBuild 3.5

I have the following project structure:

trunk/MainSolution.sln
trunk/Build/MyBuild.Proj
trunk/Library/...
trunk/etc...

So far, I've been using the following property to find out the project root folder:

<RootFolder>$(MSBuildProjectDirectory)\..\</RootFolder>

Everything was working great, until I tried using a copy task that relied on this path. It is not resolving correctly. I basically end up getting something like this which is not valid:

C:\Projects\MyProject\Trunk\Build\..\CodeAnalysis\myfile.xml

So basically, I need to get the full path for (MSBuildProjectDirectory)'s Parent.


回答1:


Item metadata is your friend!

<Target Name="GetMSBuildProjectParentDirectory">
  <!-- First you create the MSBuildProject Parent directory Item -->
  <CreateItem Include="$(MSBuildProjectDirectory)\..\">
    <Output ItemName="MSBuildProjectParentDirectory" TaskParameter="Include"/>
  </CreateItem>

  <!-- You can now retrieve its fullpath using Fullpath metadata -->
  <Message Text="%(MSBuildProjectParentDirectory.Fullpath)"/>

  <!-- Create a property based on parent fullpath-->
  <CreateProperty Value="%(MSBuildProjectParentDirectory.Fullpath)">
    <Output PropertyName="CodeFolder" TaskParameter="Value"/>
  </CreateProperty>
</Target>


来源:https://stackoverflow.com/questions/514264/find-msbuildprojectdirectory-parent-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!