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

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

问题描述

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

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任务来处理(在构建Web项目时,我需要构建Dal Implementation设置,只是未引用).我不想硬编码路径或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. Web应用程序构建开始
  2. 所有必需的项目均已构建(已配置,因此已完成)
  3. MSBuild"AfterBuild"任务启动,并将项目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.Linq\bin\$(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天全站免登陆