查找MSBuildProjectDirectory父目录 [英] Find MSBuildProjectDirectory Parent Directory

查看:82
本文介绍了查找MSBuildProjectDirectory父目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSBuild 3.5

MSBuild 3.5

我具有以下项目结构:

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

因此,基本上,我需要获取(MSBuildProjectDirectory)父级的完整路径.

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

推荐答案

项目元数据是您的朋友!

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>

这篇关于查找MSBuildProjectDirectory父目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆