.NET 参考“复制本地"根据GAC内容设置真假 [英] .NET Reference "Copy Local" True / False Being Set Based on Contents of GAC

查看:20
本文介绍了.NET 参考“复制本地"根据GAC内容设置真假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 Win Forms 项目中遇到了一个非常有趣的问题.已经解决了.我们知道发生了什么,但我们想了解它为什么会发生.这可能会帮助将来遇到类似问题的其他人.

We had a very interesting problem with a Win Forms project. It's been resolved. We know what happened, but we want to understand why it happened. This may help other people out in the future who have a similar problem.

WinForms 项目在我们客户的两台 PC 上失败.该错误是一个不起眼的 kernel.dll 错误.该项目在其他 3 台 PC 上运行良好.

The WinForms project failed on 2 of our client's PCs. The error was an obscure kernel.dll error. The project ran fine on 3 other PCs.

我们发现我们的发布文件夹中缺少一个 .DLL(log4net.dll - 一个非常流行的开源日志库).它以前在我们的发布文件夹中.为什么在这个最新版本中缺少它?

We found that a .DLL (log4net.dll - a very popular open-source logging library) was missing from our release folder. It was previously in our release folder. Why was it missing in this latest release?

它丢失了,因为我必须在我的 Dev box 上安装了一个使用 log4net.dll 的程序并将它添加到全局程序集缓存中.

It was missing because I must have installed a program on my Dev box that used log4net.dll and it was added to the Global Assembly Cache.

当我检查解决方案对 log4net.dll 的引用时,它们被更改为copy local=FALSE".它们一定是自动更改的,因为我的 GAC 中存在 log4net.dll.

When I checked the solution's references for log4net.dll, they were changed to "copy local=FALSE". They must have changed automatically because log4net.dll was present in my GAC.

我的问题从这里开始:

为什么我对 log4net.dll 的引用从 COPY LOCAL = TRUE 更改为 COPY LOCAL = FALSE?我怀疑这是因为它是由另一个程序添加到我的 GAC 中的.

Why did my reference for log4net.dll get changed from COPY LOCAL = TRUE to COPY LOCAL = FALSE? I suspect it's because it was added to my GAC by another program.

我们怎样才能防止这种情况再次发生?就目前而言,如果我安装一个使用通用库的软件并将其添加到我的 GAC,那么我引用该 DLL 的 SLN 将从 Copy Local TRUE 更改为 FALSE.

How can we prevent this from happening again? As it stands now, if I install a piece of software that uses a common library and it adds it to my GAC, then my SLNs that reference that DLL will change from Copy Local TRUE to FALSE.

推荐答案

发生这种情况是因为如果在 GAC 中安装了程序集,则 Copy Local = True 没有任何意义.由于永远不会使用该本地副本,因此始终首先搜索 GAC.保持不变会导致严重的混乱,您会认为您正在使用本地副本,但会得到另一个副本.更改它也会引起混乱,如果您没有注意到,这可能已经在解决方案加载时通过消息框解决了.

That happened because it doesn't make any sense to have Copy Local = True if an assembly is installed in the GAC. Because that local copy will never be used, the GAC is always searched first. Leaving it unchanged would cause major confusion, you'd think you are using the local copy but get another one instead. Changing it causes a confusion too, if you don't notice it, that could perhaps have been addressed with a message box at solution load time.

Log4net 是个麻烦制造者,在野外有太多版本而没有任何部署程序来确保这些版本不会相互干扰.Apache 显然只是不想解决某些问题,而是将其留给程序员.拥有依赖于 Log4net 并对感知到的 DLL Hell 风险采取措施的产品在某种程度上是不可避免的.作为回报,给你一个 DLL 地狱问题.

Log4net is a troublemaker, there are way too many versions in the wild without any deployment procedure that ensures that those versions don't bite each other. Something Apache apparently just didn't want to address, leaving it up to the programmer instead. Having products that take a dependency on Log4net and do something about the perceived DLL Hell risk is somewhat inevitable. Giving you a DLL Hell problem in return.

除了了解您的机器上安装了什么之外,没有简单的答案.当 Visual Studio 自动更新复制本地"属性时,请考虑发布到 connect.microsoft.com 以请求警告.这是一个合理的要求.

No clean simple answers, beyond being aware what's installed on your machine. Consider posting to connect.microsoft.com to ask for a warning when Visual Studio automatically updates the Copy Local property. It is a reasonable ask.

这篇关于.NET 参考“复制本地"根据GAC内容设置真假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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