MSBuild 将另一个项目的输出复制到当前项目的输出中 [英] MSBuild copy output from another project into the output of the current project

查看:16
本文介绍了MSBuild 将另一个项目的输出复制到当前项目的输出中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我想使用 MSBuild 将输出程序集从一个项目复制到我的目标应用程序的输出目录中,而在我的 MSBuild 复制任务中没有硬编码路径.这是场景:

I have a situation where I want to copy the output assembly from one project into the output directory of my target application using MSBuild, without hard-coding paths in my MSBuild Copy task. Here's the scenario:

  • 项目 A - Web 应用程序项目
  • 项目 B - Dal 接口项目
  • 项目 C - Dal 实施项目

还有一个业务层,但与我要解决的 MSBuild 问题无关.

There is a Business layer too, but has no relevance for the MSBuild problem I'm looking to solve.

我的业务层引用了我的 Dal.Interface 项目.我的 Web 项目引用了业务层,就目前而言,进行构建会将业务层和 Dal.Interface 项目拉入输出.到现在为止还挺好.现在,为了让 Web 应用程序运行,它需要 Dal 实现.我不希望在任何地方引用实现,因为我想强制对接口进行编码并且没有引用意味着它不会出现在智能感知等中.

My business layer has a reference to my Dal.Interface project. My web project has a reference to the Business layer and as it stands, doing a build will pull the business layer and Dal.Interface projects into the output. So far, so good. Now in order for the web app to run, it needs the Dal implementation. I don't want the implementation referenced anywhere since I want to enforce coding to the interface and not having a reference means it won't show up in intellisense, etc.

所以我想我可以通过 MSBuild 复制操作作为 AfterBuild 任务来处理这个问题(我有 Dal 实现设置要在 Web 项目构建时构建,只是没有被引用).我不想在 MSBuild 参数中硬编码路径或其他任何内容,因此我试图弄清楚如何从 Web 应用程序项目的 MSBuild 文件中引用 Dal 项目的输出.

So I figured I could handle this through the MSBuild copy operation as an AfterBuild task (I have the Dal Implementation setup to build when the web project builds, just not referenced). I don't want to hard code paths or anything else in the MSBuild params, so I'm trying to figure out how to reference the output of the Dal project from the Web Application Project's MSBuild file.

所以基于上面提到的项目,这是我希望看到的:

So based on the projects mentioned above this is what I want to see happen:

  1. 开始构建网络应用程序
  2. 构建所有必需的项目(已配置,因此完成)
  3. MSBuildAfterBuild"任务启动,项目 C(Dal 实现)的输出被复制到项目 A(Web 应用)的 Bin 目录

第 3 部分是我卡住的地方.

Part 3 is where I'm stuck.

我确信这可以完成,我只是没有找到一个很好的参考来帮助.提前感谢您的帮助.

I'm sure this can be done, I'm just not finding a good reference to help out. Thanks in advance for any help.

推荐答案

我已经完成了这项工作,但我很想找到一个更简洁的解决方案,利用 MSBuild 中的内置参数(如 $(TargetDir)、等等,但要指向我想要获取输出的项目).无论如何,这是我所做的:

I have made this work, though I would love to find a cleaner solution that takes advanctage of the built-in parameters within MSBuild (like $(TargetDir), etc but to point at the project I want to grab the output for). Anyway, here is what I've done:

<Target Name="AfterBuild">
<Copy SourceFiles="$(SolutionDir)MyProject.Dal.Linqin$(Configuration)MyProject.Dal.Linq.dll" DestinationFolder="$(TargetDir)"/>
</Target>

我希望看到一个更清洁的解决方案,但现在应该这样做.

I would love to see a cleaner solution, but this should do for now.

这篇关于MSBuild 将另一个项目的输出复制到当前项目的输出中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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