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

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

问题描述

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

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

  • Project.DAL-数据访问层, 取决于较低级别的库, 例如带复制本地的Oracle.DataAccess = true
  • Project.BLL-业务逻辑层,将Project.DAL引用为 项目
  • Project.UI-UI层, 编译为可执行文件,引用 Project.BLL,默认项目
  • Project.DAL - Data access layer, depends on a lower-level library, e.g. Oracle.DataAccess w/copy local = true
  • Project.BLL - Business logic layer, references Project.DAL as project
  • Project.UI - UI layer, compiles to executable, references Project.BLL, default project

在编译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文件的计算机(或VM)上设置了自动MSBuild脚本(为此也未安装Visual Studio).这样,文件将被复制到内部版本,与使用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天全站免登陆