简体   繁体   English

RegAsm - / codebase选项何时适用?

[英]RegAsm - When is the /codebase option applicable?

I have a COM-visible DLL written in C# that I would like to use in a VB6 application. 我有一个用C#编写的COM可见DLL,我想在VB6应用程序中使用它。 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. 我有两个DLL的主要用例,我想知道/codebase选项何时适用以及何时最好在GAC中注册。


Use cases: 用例:

  1. The DLL will be loaded onto another developers PC and needs to be accessible to the VB6 IDE under the Project > References menu DLL将被加载到另一台开发人员PC上,并且需要在Project > References菜单下可以访问VB6 IDE

  2. The DLL will be loaded onto production machines when the VB6 application is released 当VB6应用程序发布时,DLL将被加载到生产机器上


Any information on the appropriate use of the /codebase would be helpful. 有关正确使用/codebase任何信息都会有所帮助。

Thanks. 谢谢。

The /codebase option is the exact equivalent of the way you used to register COM servers with Regsvr32.exe. / codebase选项与您使用Regsvr32.exe注册COM服务器的方式完全等效。 You'll have to pick a specific location for the DLL and the path to that location is written to the registry. 您必须选择DLL的特定位置,并将该位置的路径写入注册表。 That's risky , COM servers have a strong DLL Hell problem since their registration is machine-wide. 这是有风险的 ,COM服务器具有强大的DLL Hell问题,因为它们的注册是机器范围的。 When you update that DLL then any application that uses the server will be affected. 更新该DLL时, 任何使用该服务器的应用程序都将受到影响。 Not often in a good way, this very often breaks an app that was not recompiled to use the updated server. 通常不会以一种好的方式,这经常会破坏未重新编译以使用更新的服务器的应用程序。

.NET improves on that by being able to store multiple versions of a DLL as selected by their [AssemblyVersion]. .NET通过能够存储由[AssemblyVersion]选择的DLL的多个版本来改进。 The exact equivalent of the Windows side-by-side cache, the GAC for managed assemblies. Windows并行缓存的完全等价物,即托管程序集的GAC。 So old apps that were not rebuilt will continue to run unaffected, still being able to use the old DLL. 因此,未重建的旧应用程序将继续不受影响地运行,仍然可以使用旧的DLL。 That's a good way. 这是一个好方法。

Using /codebase is advisable when you are busy developing the server. 在忙于开发服务器时,建议使用/ codebase。 You can skip the extra required step that registers the DLL in the GAC. 您可以跳过在GAC中注册DLL的额外必需步骤。 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. 当你使用/ codebase时,Regasm会显示一个警告,警告你关于DLL Hell的潜力,你可以忽略它。

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. 当您让Visual Studio通过“项目”>“属性”>“构建”选项卡“注册COM互操作”复选框进行注册时,您将获得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. 但VS必须运行升级才能写入注册表。

Using Isolated COM (aka "registry-free COM") is the best way. 使用隔离COM(又名“无注册表COM”)是最好的方法。 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. 它允许您将COM服务器的副本存储在与客户端程序相同的目录中,而您根本不需要注册它。 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. 例如,Microsoft Office应用程序。

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

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