.NET / COM如何使用通过Regasm注册的多个版本? [英] How does .NET/COM work with multiple versions registered via Regasm?

查看:149
本文介绍了.NET / COM如何使用通过Regasm注册的多个版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET DLL(恰好用C ++ / CLI编写)。它的一部分我想通过COM公开。我这样做和注册它使用regasm my.dll / codebase。到现在为止还挺好。但是,然后我更改一些东西和程序集更改的版本号加上我将dll移动到一个不同的文件夹。我再次注册它,并在OLE / COM查看器中查看我的COM对象。我看到这样的东西

I have a .NET DLL (that happens to be written in C++/CLI). Parts of it I want to expose via COM. I do this and register it using "regasm my.dll /codebase". So far so good. But then I change some things and the version number of the assembly changes plus I move the dll to a different folder. I register it again and look at my COM object in OLE/COM Viewer. I see something like this


InprocServer32 [Codebase] = file://c://foo/bar/my.dll
7.0.0.0 [Class] = My.Blah.Class
7.0.0.0 [Assembly] = Sync, Version=7.0.0.0, Culture=neutral, PublicKeyToken=1dd19234234
7.0.0.0 [RuntimeVersion] = v2.0.50727
7.0.0.0 [CodeBase] = file://c:/dooby/do/my.dll
7.0.0.27397 [Class] = My.Blah.Class
7.0.0.27397 [Assembly] = Sync, Version=7.0.0.27397, Culture=neutral, PublicKeyToken=1dd19234234
7.0.0.27397 [RuntimeVersion] = v2.0.50727
7.0.0.27397 [CodeBase] = file://c://foo/bar/my.dll

有关多个版本的问题:


  1. 所以我认为注册的最后一个COM对象获胜。没关系,如果我有我的旧的7.0.0.0 COM对象注册,7.0.0.27397是一个将创建时,我实例化我的COM对象,因为我最后注册它。是正确的吗?

  1. So I think that the last COM object that was registered wins. It doesn't matter if I have my old 7.0.0.0 COM object registered, the 7.0.0.27397 is the one that will be created when I instantiate my COM object because I registered it last. Is that correct?

糟糕,我没有保留7.0.0.0对象。有什么办法摆脱它吗?有没有办法删除所有版本的COM对象,而不是进入注册表,用手敲打它?

Oops I didn't keep around the 7.0.0.0 object. Is there any way to get rid of it? Is there any way to remove all versions of a COM object other than going into the registry and whacking it by hand?

只是出于好奇,想实例化一个特定版本的我的COM对象有什么办法吗? (我使用C ++如果你想给一个代码示例)。

Just out of curiosity, if I specifically wanted to instantiate a particular version of my COM object is there any way to do that? (I'm using C++ if you wanted to give a code example).

有什么方法,我可以告诉regasm不存储版本号,它只是似乎是杂乱的事情,我看不出有什么好处。如果我的COM对象经历了重大的API更改,我只是更改GUID和progid,对吧?

Is there any way I can just tell regasm to not store the version number because it just seems to be cluttering things up and I can't see what the benefit is. If my COM object went through significant API change I'd just change the GUID and progid, right? What if I don't want to register multiple versions (I don't).


推荐答案

我总是设置我的COM可见程序集与静态AssemblyVersion正是这个原因。如果要使用版本标记的二进制文件,请改用AssemblyFileVersion。

I always set my COM visible assemblies up with a static AssemblyVersion for just this reason. If you want to have binaries tagged with a version, use AssemblyFileVersion instead.


  1. 上次注册的对象赢了:yep

  2. 不是真的。你可以把你的程序集中的ComRegisterFunction / ComUnregisterFunction属性方法自动进行清理,但如果你离开旧版本的droppings,这是唯一的方法。

  3. 不同的coclass GUID和/或ProgID(例如,MyCoClass.1,.2等)。 CoCreateInstance不知道关于版本值的任何信息 - 它们被CLR的激活器用来确保它加载正确的程序集。

  4. 最好的做法是不要更改程序集版本(往上看)。

  1. Last registered object wins: yep
  2. Not really. You can put stuff in your assembly's ComRegisterFunction/ComUnregisterFunction attributed methods to automate the cleanup, but if you leave old version droppings around, this is about the only way.
  3. You'd do it with a different coclass GUID and/or ProgID (eg, MyCoClass.1, .2, etc). CoCreateInstance doesn't know anything about the version values- they're used by the CLR's activator to ensure it loaded the right assembly.
  4. No- best thing to do is never change your assembly version (see above).

这篇关于.NET / COM如何使用通过Regasm注册的多个版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆