visual-studio “注册 COM Interop”实际上是做什么的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3534600/
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-10-22 12:22:08  来源:igfitidea点击:

What does "Register for COM Interop" actually do?

visual-studiovisual-studio-2010com-interop

提问by hackerhasid

What exactly does the VS project option "Register for COM interop" actually do? Because when I build my library with this option enabled I can call CreateObject on my library from VBScript. But if I build without this and then run regasm manually CreateObject fails. So I'm wondering -- what does VS2010 do that I'm not doing?

VS 项目选项“注册 COM 互操作”究竟做了什么?因为当我在启用此选项的情况下构建我的库时,我可以从 VBScript 调用我的库上的 CreateObject。但是如果我在没有这个的情况下构建然后手动运行 regasm CreateObject 失败。所以我想知道 - VS2010 做了哪些我没有做的事情?

采纳答案by Hans Passant

It does the same thing as running Regasm.exe with the /tlb and /codebase options. The /codebase option is probably the one you forgot. Regasm likes assuming you put the DLL in the GAC and generates a warning when you don't. The GAC is indeed a very good way to avoid DLL Hell, always a COM problem. But not appropriate on your dev machine, you don't want to pollute the GAC while developing and testing the code. It only matters on your user's machine, the one that's likely to be exposed to multiple versions.

它与使用 /tlb 和 /codebase 选项运行 Regasm.exe 的作用相同。/codebase 选项可能是您忘记的选项。Regasm 喜欢假设您将 DLL 放在 GAC 中并在您不这样做时生成警告。GAC 确实是避免 DLL Hell(始终是 COM 问题)的好方法。但不适合您的开发机器,您不想在开发和测试代码时污染 GAC。它只在您用户的机器上很重要,那台机器可能会暴露于多个版本。

Using the wrong version of Regasm.exe on a 64-bit machine is another way to get in trouble, there are usually 4 versions on your machine. Be sure to distinguish the 32-bit and 64-bit versions (c:\windows\microsoft\framework vs framework64), they write different registry keys. You want to pick the one that's compatible with the client app. Using both is okay too, .NET code can run in either mode, but pretty unusual. And distinguish between the v2.0.50727 (.NET 2.0 through 3.5SP1) and the v4.0 versions. Picking the right Visual Studio Command Prompt is half the battle.

在 64 位机器上使用错误版本的 Regasm.exe 是另一种惹麻烦的方式,您的机器上通常有 4 个版本。一定要区分 32 位和 64 位版本(c:\windows\microsoft\framework vs framework64),它们写不同的注册表项。您想选择与客户端应用程序兼容的那个。两者都使用也可以,.NET 代码可以在任一模式下运行,但非常不寻常。并区分 v2.0.50727(.NET 2.0 到 3.5SP1)和 v4.0 版本。选择正确的 Visual Studio 命令提示符是成功的一半。