如何将 .NET 程序集注册为 COM?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11322353/
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
How to register a .NET assembly as COM?
提问by user1428019
I have created a class library for a workflow on a local machine and build that. I moved the complete solution to a Tridion server and tried to register the assembly in the server using regasm.exe tool as below:
我在本地机器上为工作流创建了一个类库并构建它。我将完整的解决方案移至 Tridion 服务器并尝试使用 regasm.exe 工具在服务器中注册程序集,如下所示:
C:\User\XYZ\Desktop\>RegAsm \codebase F:\Workflow\WorkflowHandler/bin/debug/WorkflowHandler.dll
I got the following error:
我收到以下错误:
failed to load 'F:\Workflow\WorkflowHandler/bin/debug/WorkflowHandler.dll ' because it is not a valid .NET Assembly.
无法加载“F:\Workflow\WorkflowHandler/bin/debug/WorkflowHandler.dll”,因为它不是有效的 .NET 程序集。
My server details:
我的服务器详细信息:
64-bit, Windows Server 2008 R2Enterprise, and .NET Framework 4 installed.
已安装 64 位、Windows Server 2008 R2Enterprise 和 .NET Framework 4。
回答by Damir Arh
Are you sure you have the right RegAsmin your path since you're calling it by exe name only without specifying the full path? You must call the right version of RegAsm for it to work, i.e 32 or 64-bit version of .NET 4.
您确定您RegAsm的路径正确,因为您仅通过 exe 名称调用它而不指定完整路径吗?您必须调用正确版本的 RegAsm 才能使其工作,即 .NET 4 的 32 位或 64 位版本。
Try specifying the full path:
尝试指定完整路径:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /codebase F:\Workflow\WorkflowHandler\bin\debug\WorkflowHandler.dll
or
或者
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe /codebase F:\Workflow\WorkflowHandler\bin\debug\WorkflowHandler.dll
Also I noticed that in the path to your assembly you had some /characters instead of \. Make sure you're putting in the correct path.
我还注意到,在你的程序集的路径中,你有一些/字符而不是\. 确保您放置在正确的路径中。
回答by Jamie
I'll expand on the accepted answer with my solution.
我将用我的解决方案扩展已接受的答案。
First, I ran into issues with "AnyCPU" (I have to interop with COM, hence my reason for doing this), so I limit platform to x86 and x64. I wanted it to register the component as part of the build, so I did this as a post build event:
首先,我遇到了“AnyCPU”的问题(我必须与 COM 互操作,因此我这样做的原因),所以我将平台限制为 x86 和 x64。我希望它将组件注册为构建的一部分,因此我将其作为构建后事件进行:
if $(PlatformName) == x64 (
set RegAsm=$(MSBuildFrameworkToolsPath64)regasm.exe
) else (
set RegAsm=$(MSBuildFrameworkToolsPath)regasm.exe
)
echo Creating TypeLib
"%RegAsm%" /tlb "$(TargetPath)"
echo Registering Component
"%RegAsm%" "$(TargetPath)"
Note: This probably won't work for ia64. If you've got to make this work for one of those, you've got bigger problems than this, though. :-)
注意:这可能不适用于 ia64。但是,如果您必须为其中之一进行这项工作,那么您会遇到比这更大的问题。:-)

