将互操作dll放入GAC中?
这可能是一个有点愚蠢的问题,但我需要一些澄清。我对 .NET 有点陌生,并且创建了一个必须引用现有 COM DLL 的 EXE。在此过程中,Visual Studio 2010 自动创建了一个“Interop”DLL,它需要/使用它来与旧版 COM DLL 配合使用。
我已经部署了我的项目并将此 Interop DLL 包含在其中(在同一文件夹中),并且一切正常。但是,我还有其他应用程序需要使用相同的旧版 COM DLL。是否可以在每个应用程序中以相同的方式引用它,并继续在每个应用程序中部署“Interop”DLL?不幸的是,所有这些小应用程序都位于同一个文件夹中,并且每个应用程序都使用相同的 Interop DLL(因此,如果另一个应用程序使用它,它就已经存在于该文件夹中。)我被迫将它们放在同一个文件夹中,因为这些应用程序正在被作为定制父应用程序的一种方式调用。因此,当它想要运行“自定义”应用程序时,它只会在本地文件夹中查找。我只是担心如果一个 EXE 被删除并且他们删除了 Interop DLL,那么仍然依赖它的其他人将会失败。
所以,我想知道将 Interop DLL 放入 GAC 中是否可能或者是个好主意?我继续将 Interop DLL 安装到 GAC 中,然后从运行 EXE 的文件夹中删除 Interop DLL,但它无法工作。我收到一条错误消息“无法加载文件或程序集”。我坚持让这个工作。
- 我是否需要在项目中以不同方式引用 Interop DLL,以便它现在来自 GAC? 或者
- 我是否需要在 .NET 代码中添加一些内容(例如 Assembly.Load)才能使其正常工作?
- 我需要使用 TBIMP 自己创建 Interop DLL 吗?
任何帮助将不胜感激!
最好的问候,
纳尔逊
This might be a bit of stupid question but I need some clarification. I'm somewhat new to .NET and have created a EXE that had to reference an existing COM DLL. In doing so, Visual Studio 2010 automatically created an "Interop" DLL that it needs/uses to work with the legacy COM DLL.
I have deployed my project and included this Interop DLL with it (in the same folder) and everything is working fine. However, I have other applications that will need to use this same legacy COM DLL. Is it okay to reference it they same way in each application and keep deploying the "Interop" DLL with each application? Unfortuantely, all of these small applications go in the same folder and each use the same Interop DLL (so it will already exist there if it's used by another app.) I'm forced to having them in the same folder because these applications are being called as a way of customizing a parent application. As such it only looks in it's local folder when it wants to run a "custom" app. I'm just concerned if one the EXE's is ever removed and they take out the Interop DLL, then the others that still depend on it will fail.
So, I was wondering if it is possible or a good idea to put that Interop DLL in the GAC? I went ahead and installed the Interop DLL into the GAC and then removed the Interop DLL from the folder where my EXE runs and it failed to work. I get an error that says "Could not load file or assembly". I'm stuck on getting this working.
- Do I need to reference the Interop DLL in my project differently such that it's now from the GAC?
or - Do I need to add something to my .NET code like Assembly.Load to make it work?
- Do I need to create that Interop DLL myself using TLBIMP?
Any help would be greatly appreciated!
Best Regards,
Nelson
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这称为 PIA,“主要互操作程序集”。您可以使用 Tlbimp.exe 的 /primary 选项生成它们,操作方法在这里。
在某些情况下,您必须拥有一个 PIA,当您的一个程序集将导入库中的类型公开到另一个程序集(该程序集运行时加载了互操作库的单独副本)时,就需要 PIA。显然这不是你的情况。它也在走渡渡鸟的路,VS2010支持“嵌入互操作类型”功能,这是一个非常理想的功能,重要的库完全消失。
对于你的情况我不会打扰。将其放入 GAC 没有任何好处,只会让人头疼。否则不知道为什么会遇到麻烦,请使用 Fuslogvw.exe 来解决程序集解析问题。
That's called a PIA, "Primary Interop Assembly". You generate them with the /primary option to Tlbimp.exe, the HowTo is here.
In some cases you have to have a PIA, required when one of your assemblies exposes a type from the import library to another assembly that runs with a separate copy of the interop library loaded. Clearly that's not your case. It is going the way of dodo too, VS2010 supports the "Embed Interop Types" feature, a very desirable feature where important libraries completely disappear.
In your case I would not bother. There's just no advantage to putting it in the GAC, only headaches. Otherwise no idea why you have trouble, use Fuslogvw.exe to troubleshoot assembly resolution problems.
您可以使用 ILmerge 制作单个 .dll 文件并部署将此纳入广汽集团。
附言。如果您使用的是 VS.NET 2010,则可以使用
Embed Interop types
项目属性You can use ILmerge to make a single .dll file and deploy this into GAC.
PS. If you are using VS.NET 2010 you can use the
Embed Interop types
project property, look here.