regasm /codebase works but file generated with regasm /codebase /regfile does not

喜夏-厌秋 提交于 2020-01-05 07:37:07

问题


I have a COM visible dll suitable for 32 and 64 bit architechtures that I use to add a menu item to the windows explorer context menu. Using "regasm myassembly.dll /codebase" I register the dll and see the new menu item. Great. Unregistering works fine also.

Now I want to create a .reg file so I can add the menu item to non development machines. I use "regasm myassembly.dll /codebase /regfile" that produces a reg file that I can import with regedit. The problem is, after importing the .reg, I cannot see the menu icon. Why might the registration have failed? Note I am on a 64 bit system.


回答1:


Registering a shell extension requires writing more registry keys than normally required to register a [ComVisible] .NET assembly.
You also have to write the keys that Explorer reads to discover extensions.
You didn't mention at all how you took care of that, this normally requires a custom [ComRegisterFunction]. But sure, the .reg file isn't going to contain those keys since a custom registration function requires running code.




回答2:


You should know that this is a really, really, bad idea. Please read this classic post on the subject.

http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx

Then this recent update:

http://blogs.msdn.com/b/oldnewthing/archive/2013/02/22/10396079.aspx

Even if you insisted on trying this (or if the assembly was intended for something other that an Add-in), it's still a bad idea to try to use a .reg file to register the assembly.

There is a lot more that would need to happen besides the COM registration for the assembly to work. Most likely you would have to add it to the GAC so that .NET can find it. Also, a future version of .NET might require more information, or different information, to be added on the registry. Even today (I suspect), REGASM might need to put different information on different environments (x86 vs. x64).



来源:https://stackoverflow.com/questions/15834410/regasm-codebase-works-but-file-generated-with-regasm-codebase-regfile-does-no

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!