Visual Studio 如何确定使用多项目解决方案将哪些内容复制到输出目录? [英] How does visual studio determine what to copy to the output directory with multi-project solutions?

查看:18
本文介绍了Visual Studio 如何确定使用多项目解决方案将哪些内容复制到输出目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个具有以下结构的解决方案:

Let's say we have a solution with the following structure:

  • Project.DAL - 数据访问层,依赖于较低级别的库,例如Oracle.DataAccess w/copy local=真
  • Project.BLL - 业务逻辑层,将 Project.DAL 引用为项目
  • Project.UI - UI 层,编译成可执行文件,引用Project.BLL,默认项目

编译 Project.UI 时,VS 很聪明,可以将 Project.DAL.dll 复制到输出目录,但它不够聪明,无法确定我希望 Oracle.DataAccess 也被复制到输出目录分发给客户.

When Project.UI is compiled, VS is smart enough to copy Project.DAL.dll to the output directory, but it's not smart enough to figure out that I wanted Oracle.DataAccess to be copied to the output directory as well for distribution to clients.

谁能解释为什么会这样?是因为它在 GAC 中看到 Oracle.DataAccess 并假设客户端也会在 GAC 中拥有它吗?

Can anyone explain why this is so? Is it because it sees Oracle.DataAccess in the GAC and assumes that clients will have it in the GAC as well?

这没什么大不了的,但有点烦人的是,每次我添加新的程序集引用时,我都必须记住将其设置为复制本地并添加一个项目以在我的构建脚本中复制它.

It's not that big of a deal, but it's kinda annoying that every time I add a new assembly reference, I have to remember to set it to copy local and add an item to copy it in my build script as well.

推荐答案

是的,Visual Studio 会在以下两种情况下将 DLL 复制到输出路径:

Yes, Visual Studio will copy a DLL to the output path in any of the two conditions below:

  1. 使用 CopyLocal = true 显式引用 DLL
  2. 该 DLL 在没有 CopyLocal 的情况下被引用或通过其他一些引用的 DLL 隐式引用并且不在 GAC 中

当文件在 GAC 中时它不会复制本地的原因是,在解析程序集名称时 GAC 具有最高优先级,即即使您有(不同的)本地副本,来自 GAC 的版本也将是用过.

The reason why it will not copy-local when the file is in GAC, is that when resolving assembly names the GAC has highest priority, i.e. even if you have a (different) local copy, the version from the GAC will be used.

我建议您设置一个库目录,在其中放置所有引用的外部程序集.然后,您在没有 Oracle 文件 gac'ed(也没有为此安装 Visual Studio)的计算机(或 VM)上设置一个自动 MSBuild 脚本.这样,文件将被复制到构建中,与使用 VS 时相比,您可以更好地控制所做的事情.

I suggest you set up a library directory where you put all external assemblies that are referenced. Then you set up an automatic MSBuild script on a computer (or VM) that does not have the Oracle-file gac'ed (nor Visual Studio installed for that sake). That way, the file will be copied to the build, and you will have more control over what is done than when using VS.

这篇关于Visual Studio 如何确定使用多项目解决方案将哪些内容复制到输出目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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