如何使用Visual Studio.Net创建和部署COM对象

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the classes in Visual Studio.

本文介绍了在Visual Studio中创建COM类并通过专业MSI创作工具部署COM类时可能出现的相对困难和非显而易见的问题。 假定读者已经熟悉Visual Studio中的类。

   1. Create a class and compile into, say, mydll.dll.

1.创建一个类,然后编译为mydll.dll。

   2. Open Properties of the assembly, and check “Make assembly COM-visible”. There’s related checkbox under Build - “Register for COM interop”. That one is related to the local machine of the developer, it registers just-built dll. This may be handy later if Wise product is used to create the MSI - Wise needs COM object registered on the machine in order to extract its COM information. The registration can be later cleaned up from the developer’s machine by using action “Clean” from the menu “Build” - cleaning will unregister the dll.

2.打开装配的属性,然后选中“使装配COM可见”。 在“构建”-“注册COM互操作”下有一个相关的复选框。 那与开发人员的本地计算机有关,它注册刚构建的dll。 如果使用Wise产品创建MSI,稍后可能会很方便-Wise需要在计算机上注册COM对象才能提取其COM信息。 稍后可以通过使用菜单“构建”中的“清洁”操作从开发人员的计算机中清除注册-清洁将注销该dll。

   3. Sign the assembly. Depending on where it's going to be used, you can generate new certificate, of use the one already trusted by the domain where the library will be used.

3.在组件上签名。 根据要使用的位置,您可以生成新的证书,使用的证书将由使用该库的域信任。

Why: because when this dll is deployed, .Net won’t allow it to be used by other applications unless it has strong name.
原因:因为部署此dll时,.Net除非具有强名,否则将不允许其他应用程序使用它。

  4. Open bin/release folder, and extract COM information from the mydll.dll, by running regasm /codebase /regfile:mydll.reg mydll.dll . If you forgot #3 above, regasm will show an error to the same effect.

4.打开bin / release文件夹,然后通过运行regasm / codebase /regfile:mydll.reg mydll.dll从mydll.dll中提取COM信息。 如果您忘记了上面的#3,则重新加气将显示错误,效果相同。

   5. Open mydll.reg and visually inspect it. For instance, if mydll.dll was using webservice (such as UPS or Fedex ones), all public members of the webservices will be exposed by the COM object - which is probably not what we want. If so, delete them.

5.打开mydll.reg并进行直观检查。 例如,如果mydll.dll使用的是Web服务(例如UPS或Fedex的),则COM对象将公开Web服务的所有公共成员-这可能不是我们想要的。 如果是这样,请删除它们。

   6. Create the MSI. Mydll.dll can be placed either in its own directory, or in GAC. If it’s placed in its own directory, then the above command regasm does not need parameter /codebase. /codebase creates an extra registry value in .reg file that will tell Framework where the actual dll is. Without it, Framework will be looking in GAC and in %path%, and won’t find it.

6.创建MSI。 Mydll.dll可以放在其自己的目录中,也可以放在GAC中。 如果将其放置在自己的目录中,则上述命令regasm不需要参数/ codebase 。 / codebase在.reg文件中创建一个额外的注册表值,该值将告诉Framework实际dll在哪里。 没有它,Framework将在GAC和%path%中查找,并且找不到。

   7. Import mydll.reg into the same component in the MSI as mydll.dll. Inspect visualy, and if the path of mydll.dll appears hardcoded from the developer’s machine, replace it by [#filekey], where filekey is the key of mydll.dll in the table File in the MSI.

7.将mydll.reg导入到MSI中与mydll.dll相同的组件中。 检查外观,如果mydll.dll的路径似乎是从开发人员的机器硬编码的,则将其替换为[ ,其中File中的mydll.dll的键。

   8. The above is sufficient for runtime operation of the library. If the development with this library as a reference is in the plans as well, then in addition to the dll itself we also need to generate and deploy type library.

8.以上内容足以满足库的运行时操作。 如果计划中也以该库为参考进行开发,那么除了dll本身之外,我们还需要生成和部署类型库。

   9. To generate the type library, run regasm /codebase /tlb:mydll.tlb mydll.dll . This will create new file mydll.tlb.

9.要生成类型库,请运行regasm / codebase /tlb:mydll.tlb mydll.dll 。 这将创建新文件mydll.tlb。

  10. Include mydll.tlb in the installation as new component, with extracting COM information. In the light of the latest recommendations, delete advertising information about Typelib if it was extracted (i.e. delete the contents of the table Typelib in the MSI), but ensure that the equivalent entry is present in Registry table.

10.将mydll.tlb作为新组件包含在安装中,并提取COM信息。 根据最新建议,请删除有关Typelib的广告信息(如果已提取)(例如,删除MSI中的Typelib表的内容),但要确保注册表项中存在等效条目。

  11. Visually verify that registry information for the typelib includes keys HELPDIR and win32.

11.直观地验证typelib的注册表信息是否包含项HELPDIR和win32。

翻译自: https://www.experts-exchange.com/articles/4456/How-to-create-and-deploy-COM-object-with-Visual-Studio-Net.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值