.net 使用 Visual Studio 安装项目自动注册和 GAC 一个 COM Interop DLL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3087063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 14:25:50  来源:igfitidea点击:

Use Visual Studio Setup Project to automatically register and GAC a COM Interop DLL

.netinteropgacsetup-projectregasm

提问by Ben McCormack

I've created a .NET assembly for COM interop and it is working well on my development machine. I'm currently trying to figure out how to deploy the DLL to a target machine using Visual Studio's "Setup Project." How can I use the VIsual Studio setup project to do the following things:

我已经为 COM 互操作创建了一个 .NET 程序集,它在我的开发机器上运行良好。我目前正在尝试弄清楚如何使用 Visual Studio 的“安装项目”将 DLL 部署到目标机器。如何使用 VIsual Studio 安装项目执行以下操作:

  • Register the assembly (currently using regasm).
    • The assembly needs to be registered successfullyand the type library (.tlb) needs to be registered successfully.
    • This answersuggests scrapping regasmin favor of custom code. I this is a good idea? If so, how does this code get included in the setup project?
    • This answersuggests using the /regfilecommand of regasmand then using the import tool on the Registry in the Setup Project. Will this work?
  • Install the assembly in the GAC (currently using gacutil)
    • I'm aware of the "Global Assembly Cache Folder" in the "File System on Target Machine." Is there anything special I need to do in including the assembly in the setup project?
  • 注册程序集(当前使用regasm)。
    • 程序集需要成功注册,类型库 (.tlb) 需要成功注册
    • 这个答案建议报废regasm以支持自定义代码。我这是个好主意吗?如果是这样,此代码如何包含在安装项目中?
    • 这个答案建议使用/regfile命令,regasm然后使用安装项目中注册表上的导入工具。这会起作用吗?
  • 在 GAC 中安装程序集(当前使用gacutil
    • 我知道“目标机器上的文件系统”中的“全局程序集缓存文件夹”。在安装项目中包含程序集时,我需要做什么特别的事情吗?

Any other advice or concerns would be much appreciated.

任何其他建议或疑虑将不胜感激。

回答by Hans Passant

Gacutil.exe won't be available on the target machine. Not a problem, MSI can get the job done. Right-click "File System on Target Machine", Add, GAC. Right-click that added folder, Add, Project Output. That ensures the assembly is gac-ed.

Gacutil.exe 在目标机器上将不可用。没问题,MSI 可以完成工作。右键单击“目标机器上的文件系统”,添加,GAC。右键单击添加的文件夹,添加,项目输出。这确保了程序集是gac-ed。

It can also register the assembly like Regasm.exe does. Set the Register property of the project output reference to vsdrpCOM.

它还可以像 Regasm.exe 一样注册程序集。将项目输出引用的 Register 属性设置为 vsdrpCOM。