RegAsm -/codebase 选项何时适用? [英] RegAsm - When is the /codebase option applicable?

查看:69
本文介绍了RegAsm -/codebase 选项何时适用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 C# 编写的 COM 可见 DLL,我想在 VB6 应用程序中使用它.我有 DLL 的两个主要用例,我想知道 /codebase 选项何时适用以及何时在 GAC 中注册更好.

I have a COM-visible DLL written in C# that I would like to use in a VB6 application. I have two main use cases of the DLL and am wondering when the /codebase option is applicable and when it is better to register in the GAC.


用例:

  1. DLL 将被加载到另一台开发人员 PC 上,并且需要在 Project > 下的 VB6 IDE 中可以访问.参考菜单

当 VB6 应用程序发布时,DLL 将被加载到生产机器上

The DLL will be loaded onto production machines when the VB6 application is released


有关适当使用 /codebase 的任何信息都会有所帮助.

Any information on the appropriate use of the /codebase would be helpful.

谢谢.

推荐答案

/codebase 选项与您使用 Regsvr32.exe 注册 COM 服务器的方式完全等效.您必须为 DLL 选择一个特定位置,并将该位置的路径写入注册表.这是风险,COM 服务器有一个强大的 DLL Hell 问题,因为它们的注册是机器范围的.当您更新该 DLL 时,任何 使用该服务器的应用程序都将受到影响.这并不常见,这通常会破坏未重新编译以使用更新后的服务器的应用程序.

The /codebase option is the exact equivalent of the way you used to register COM servers with Regsvr32.exe. You'll have to pick a specific location for the DLL and the path to that location is written to the registry. That's risky, COM servers have a strong DLL Hell problem since their registration is machine-wide. When you update that DLL then any application that uses the server will be affected. Not often in a good way, this very often breaks an app that was not recompiled to use the updated server.

.NET 通过能够存储由其 [AssemblyVersion] 选择的 DLL 的多个版本来改进这一点.完全等同于 Windows 并行缓存,即托管程序集的 GAC.因此,未重建的旧应用程序将继续运行,不受影响,仍然能够使用旧 DLL.这是个好方法.

.NET improves on that by being able to store multiple versions of a DLL as selected by their [AssemblyVersion]. The exact equivalent of the Windows side-by-side cache, the GAC for managed assemblies. So old apps that were not rebuilt will continue to run unaffected, still being able to use the old DLL. That's a good way.

当您忙于开发服务器时,建议使用/codebase.您可以跳过在 GAC 中注册 DLL 的额外必需步骤.忘记这样做很痛苦,您的更改似乎不起作用,因为测试应用程序将加载旧版本.当你使用/codebase 时,Regasm 会显示警告,警告你关于 DLL Hell 的潜力,你可以忽略它.

Using /codebase is advisable when you are busy developing the server. You can skip the extra required step that registers the DLL in the GAC. Forgetting to do so is painful, your changes won't seem to work because the test app will load the old version. Regasm will display a warning when you use /codebase, warning you about the DLL Hell potential, you can ignore it.

当您让 Visual Studio 使用项目">属性">构建"选项卡、注册 COM 互操作"复选框进行注册时,您将获得与 Regasm/codebase/tlb 完全等效的内容.这样做更可取,因为它还能确保旧版本的程序集不被注册,从而避免注册表污染.但是 VS 必须运行提升才能写入注册表.

When you let Visual Studio take care of the registration with the Project > Properties > Build tab, "Register for COM interop" checkbox then you get the exact equivalent of Regasm /codebase /tlb. It is more desirable to do it this way because it also ensures that the old version of the assembly gets unregistered, thus avoiding registry pollution. But VS has to run elevated so it can write to the registry.

使用隔离 COM(又名免注册 COM")是最好的方法.它允许您将 COM 服务器的副本存储在与客户端程序相同的目录中,而您根本不必注册它.然而,这需要修改客户端程序,如果您对客户端应用程序没有任何控制权,或者它是其他人喜欢弄乱的那种应用程序,则这很困难.例如 Microsoft Office 应用.

Using Isolated COM (aka "registry-free COM") is the best way. It lets you store a copy of the COM server in the same directory as the client program and you don't have to register it at all. That however requires tinkering with the client program, difficult if you don't have any control over the client app or if it is the kind of app that other people like to mess with. Microsoft Office apps for example.

这篇关于RegAsm -/codebase 选项何时适用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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