如何从具有相对文件路径的另一个 msbuild 项目导入 msbuildcommunitytasks 项目? [英] How do I import the msbuildcommunitytasks project from another msbuild project with a relative file path?

查看:22
本文介绍了如何从具有相对文件路径的另一个 msbuild 项目导入 msbuildcommunitytasks 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请放轻松,我是 msbuild 和 msbuildtasks 的新手!

Please go easy I am new to msbuild and msbuildtasks!

如何设置一个属性,该属性表示我要导入的目标文件的相对文件路径?我需要相对引用,以便它适用于所有开发机器.但是导入的目标试图在内部使用相对文件路径,这将不起作用,因为它是相对于导入的目标重新评估的!

How can I set a property which represents a relative file path to a targets file which I want to import? I need relative references so it will work on all dev machines. But the target for import is trying to use the relative file path internally, which won't work as it is re-evaluated relative to the imported target!

实际上,我正在尝试解决导入的 记录在案的行为项目:

Effectively I am trying to work around the documented behaviour of imported projects:

导入的所有相对路径项目被解释为相对于导入项目的目录.因此,如果一个项目文件是导入到几个项目文件中不同地点,相对导入项目文件中的路径会有不同的解释每个导入的项目.

All relative paths in imported projects are interpreted relative to the directory of the imported project. Therefore, if a project file is imported into several project files in different locations, the relative paths in the imported project file will be interpreted differently for each imported project.

推荐答案

好的,我找到了答案.本质上,您必须将属性 MSBuildCommunityTasksPath 设置为返回到原始包含目录的相对路径.

Ok, I've found the answer. Essentially you have to set the property MSBuildCommunityTasksPath as a relative path back to the original containing directory.

例如,给定这样的文件夹结构:

For example, given a folder structure like this:

Root---project---Build---{My msbuild project}||-Tools---MSBuildCommunityTasks---{二进制文件和目标}

Root---project---Build---{My msbuild project}
           |
           |-Tools---MSBuildCommunityTasks---{Binaries and Targets}

要让目标项目通过属性 MSBuildCommunityTasksPath 引用其二进制文件,它会找到这样的任务文件:

To get the targets project to reference its binaries via the property MSBuildCommunityTasksPath, it will find the tasks file like this:

<PropertyGroup>
    <MSBuildCommunityTasksPath>..MSBuildCommunityTasks</MSBuildCommunityTasksPath> <!--Relative path back to yourself-->
</PropertyGroup>

然后您可以使用另一个相关文件引用导入目标文件:

Then you can import the targets file with another relative file reference :

  <Import Project="....ToolsMSBuildCommunityTasksMsBuild.Community.Tasks.Targets"/>

这篇关于如何从具有相对文件路径的另一个 msbuild 项目导入 msbuildcommunitytasks 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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