visual-studio Visual Studio 将 dll 引用复制到输出文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3635716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
visual studio copy dll references to output folder
提问by user434541
I am trying to extend a certain application. I am using a DLL which comes bundled with that application to extend its functionality. I am using visual studio 2010 express edition. I added a reference to the dll library. In the reference properties the option "Copy local" is disabled.(greyed out) why is that? I want visual studio to copy the dll to my release folder. If this can't be done is there another way to bundle the dll?
我正在尝试扩展某个应用程序。我正在使用与该应用程序捆绑在一起的 DLL 来扩展其功能。我正在使用 Visual Studio 2010 速成版。我添加了对 dll 库的引用。在参考属性中,“复制本地”选项被禁用。(变灰)为什么会这样?我希望 Visual Studio 将 dll 复制到我的发布文件夹。如果这不能完成,是否有另一种方法来捆绑 dll?
回答by JaredPar
Your comment to Hans answer indicates this is a COM assembly and that you are using Visual Studio 2010.
您对 Hans 回答的评论表明这是一个 COM 程序集,并且您使用的是 Visual Studio 2010。
This means the assembly reference was likely added with the "Embed Interop Types" setting set to true. This has the effect of linking the COM assembly into your binary removing the need to deploy it altogether. The following link has a more detailed explanation
这意味着程序集引用可能是在“嵌入互操作类型”设置设置为 true 的情况下添加的。这具有将 COM 程序集链接到二进制文件的效果,无需完全部署它。下面的链接有更详细的解释
If you do want to deploy it though then will need to do the following
如果您确实想部署它,则需要执行以下操作
- Click on the reference in the references tab
- Hit F4 to bring up the properties grid
- Set "Embed Interop Types" to False (this will ungray Copy Local)
- Set "Copy Local" to true
- 单击参考选项卡中的参考
- 按 F4 调出属性网格
- 将“嵌入互操作类型”设置为 False(这将取消复制本地)
- 将“复制本地”设置为 true
回答by Hans Passant
It depends on what kind of DLL it is. If it is a COM server then Copy Local is off when you have a PIA registered for that COM server. If it is a regular .NET assembly then it will be off when it is registered in the GAC.
这取决于它是什么类型的 DLL。如果它是 COM 服务器,则当您为该 COM 服务器注册了 PIA 时,复制本地将关闭。如果它是一个常规的 .NET 程序集,那么当它在 GAC 中注册时它将被关闭。
Fix the issue by, respectively, using regasm /u to unregister the PIA or gacutil /u to remove it from the GAC. Do note that you might not want to do this if this DLL requires that its installer is executed on the target machine. Which is likely. Talk to the component vendor or author to find out what you should do.
通过分别使用 regasm /u 取消注册 PIA 或使用 gacutil /u 将其从 GAC 中删除来修复该问题。请注意,如果此 DLL 要求在目标计算机上执行其安装程序,则您可能不想这样做。这是可能的。与组件供应商或作者交谈以了解您应该做什么。

