复制本地如何工作?log4net.dll 没有被复制到 MyProject 输出目录

How does Copy-local work? log4net.dll is not being copied to MyProject output directory(复制本地如何工作?log4net.dll 没有被复制到 MyProject 输出目录)

本文介绍了复制本地如何工作?log4net.dll 没有被复制到 MyProject 输出目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道引用的 copy-local=true 到底是做什么的.它是否将引用的程序集及其所有依赖项复制到输出目录?

I am wondering what copy-local=true for references exactly does. Does it copy the referenced assembly along with all of its dependencies to the output directory?

我的情况如下:我有一个使用 log4net 的自定义日志包装器.我构建了一个 MyLogWrapper.dll 的发布程序集,其中 log4net.dll 引用设置为 copy-local true.从 MyProject 引用 MyLogWrapper.dll 并将本地复制设置为 true 应该会导致 log4net.dll 也被复制,对吗?我只在 MyProject 中引用 MyLogWrapper.dll 而没有它的依赖项.log4net.dll 没有被复制到 MyProject 输出目录,但 MyLogWrapper 的所有其他依赖项都是.可能是什么问题?

My scenario is the following: I have a custom log wrapper that utilizes log4net. I build a release assembly of MyLogWrapper.dll with log4net.dll reference set to copy-local true. Referencing MyLogWrapper.dll from MyProject with copy local set to true should result in log4net.dll being copied as well right? I am only referencing MyLogWrapper.dll and none of its dependencies in MyProject. log4net.dll is not being copied to MyProject output directory but all other dependencies of MyLogWrapper are. What could be the problem?

我做了更多的实验,似乎如果我从 GAC 中删除程序集 (log4net.dll),它就会开始在本地复制.谁能确认这是问题所在?

I have made some more experiments and it seems that if I remove the assembly (log4net.dll) from GAC it starts to get copied locally. Can anyone confirm that this is the problem?

推荐答案

不幸的是,根据从 MSDN 文档 对于 GAC 中的程序集,CopyLocal 功能无法按预期工作.

Unfortunately it appears that according to the following statement taken from the MSDN documentation the CopyLocal functionality does not work as expected for assemblies already in the GAC.

如果您部署的应用程序包含对在 GAC 中注册的自定义组件的引用,则无论 CopyLocal 设置如何,该组件都不会随应用程序一起部署.在 Visual Studio 的早期版本中,您可以在引用上设置 CopyLocal 属性以确保部署程序集.现在,您必须手动将程序集添加到 Bin 文件夹.这将审查所有自定义代码,降低发布您不熟悉的自定义代码的风险.

If you deploy an application that contains a reference to a custom component that is registered in the GAC, the component will not be deployed with the application, regardless of the CopyLocal setting. In previous versions of Visual Studio, you could set the CopyLocal property on a reference to ensure that the assembly was deployed. Now, you must manually add the assembly to the Bin folder. This puts all custom code under scrutiny, reducing the risk of publishing custom code with which you are not familiar.

更多信息可以在以下页面中找到,该页面解释了有关项目引用如何工作的详细信息.

More information can be found at the following page which explains details about how project references work.

MSDN:项目参考

这篇关于复制本地如何工作?log4net.dll 没有被复制到 MyProject 输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:复制本地如何工作?log4net.dll 没有被复制到 MyProject 输出目录

基础教程推荐