简体   繁体   English

将interop dll放入GAC?

[英]Put interop dll into GAC?

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. 我对.NET有点新,并创建了一个必须引用现有COM DLL的EXE。 In doing so, Visual Studio 2010 automatically created an "Interop" DLL that it needs/uses to work with the legacy COM DLL. 在这样做时,Visual Studio 2010自动创建了一个“Interop”DLL,它需要/使用它来处理旧的COM DLL。

I have deployed my project and included this Interop DLL with it (in the same folder) and everything is working fine. 我已经部署了我的项目并将它包含在这个Interop DLL中(在同一个文件夹中),一切正常。 However, I have other applications that will need to use this same legacy COM DLL. 但是,我有其他应用程序需要使用相同的传统COM DLL。 Is it okay to reference it they same way in each application and keep deploying the "Interop" DLL with each application? 可以在每个应用程序中以相同的方式引用它并继续在每个应用程序中部署“Interop”DLL吗? 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. 不幸的是,所有这些小应用程序都在同一个文件夹中,并且每个都使用相同的Interop DLL(因此,如果它被其他应用程序使用,它就已存在。)我被迫将它们放在同一个文件夹中,因为这些应用程序正在被称为自定义父应用程序的一种方式。 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. 我只是担心如果一个EXE被删除并且他们取出Interop DLL,那么仍​​然依赖它的其他人将会失败。

So, I was wondering if it is possible or a good idea to put that Interop DLL in the GAC? 所以,我想知道将Interop DLL放入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. 我继续将Interop DLL安装到GAC中,然后从我运行EXE的文件夹中删除了Interop DLL,但它无法正常工作。 I get an error that says "Could not load file or assembly". 我收到一条错误消息“无法加载文件或程序集”。 I'm stuck on getting this working. 我坚持让这个工作。

  1. Do I need to reference the Interop DLL in my project differently such that it's now from the GAC? 我是否需要以不同方式引用我项目中的Interop DLL,以便它现在来自GAC? or 要么
  2. Do I need to add something to my .NET code like Assembly.Load to make it work? 我是否需要在我的.NET代码中添加一些东西,比如Assembly.Load才能使它工作?
  3. Do I need to create that Interop DLL myself using TLBIMP? 我是否需要使用TLBIMP自己创建Interop DLL?

Any help would be greatly appreciated! 任何帮助将不胜感激!

Best Regards, 最好的祝福,

Nelson 纳尔逊

That's called a PIA, "Primary Interop Assembly". 这被称为PIA,“主要互操作组件”。 You generate them with the /primary option to Tlbimp.exe, the HowTo is here . 你用Tlbimp.exe的/ primary选项生成它们,HowTo 在这里

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. 在某些情况下,您需要有一个PIA,当您的某个程序集将一个类型从导入库暴露给另一个使用加载的互操作程序库的单独副本运行的程序集时需要。 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. 它也是渡渡鸟的方式,VS2010支持“嵌入互操作类型”功能,这是一个非常理想的功能,重要的库完全消失。

In your case I would not bother. 在你的情况下,我不会打扰。 There's just no advantage to putting it in the GAC, only headaches. 把它放入GAC没有任何好处,只有头痛。 Otherwise no idea why you have trouble, use Fuslogvw.exe to troubleshoot assembly resolution problems. 否则不知道为什么你遇到麻烦,使用Fuslogvw.exe来解决程序集解决问题。

You can use ILmerge to make a single .dll file and deploy this into GAC. 您可以使用ILmerge生成单个.dll文件并将其部署到GAC中。

PS. PS。 If you are using VS.NET 2010 you can use the Embed Interop types project property, look here . 如果您使用的是VS.NET 2010,则可以使用Embed Interop types项目属性,请查看此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM