COM互连体并排组件 [英] COM interop side-by-side assemblies

查看:213
本文介绍了COM互连体并排组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要部署同一个C#.NET项目的多个版本。项目输出是要在本机应用程序中使用的COM互操作程序集。我所遇到的问题是,我必须部署这个程序集的几个版本,但不管我做什么似乎没有创建不同的版本。



我试过更改程序集GUID,尝试更改程序集版本号,尝试重新生成程序集名称键,尝试更改程序集标题和描述。我不想为了版本控制而更改程序集中各个类型的GUID或名称。



如何确保这些版本不会覆盖eachother,

 <$> 

c $ c> using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

命名空间InteropTest
{
[Guid(...)]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Test
{
public Test()
{
}

public string版本
{
get
{
return1.0;
}
}
}
}


解决方案


我不想为了版本控制而更改程序集中各个类型的GUID或名称。


但是确切你必须做什么以防止COM类型互相干扰。 [Guid]用于在注册COM类的HKLM \Software\Classes\CLSID中选择注册表项。具有相同Guid的两个不同版本将覆盖彼此的键。否则称为DLL地狱。更改公共接口需要新的Guid,以确保使用旧版本的客户端不会死于不可能诊断不当行为。一个艰难的COM需求。



省略[Guid]属性是非常可能的,你现在把它留给CLR为你生成一个。现在,程序集属性开始起作用,guid值由包含程序集名称和版本以及接口上的方法集及其参数的光滑算法自动生成。因此,确保任何更改自动生成不同的guid。并且,如预期和需要,一个不同的[AssemblyVersion]将产生一个不同的[Guid]。



另一种方法,这是我假设你的意思与'side-by侧,是注册程序集,但依赖于清单。它必须嵌入在客户端程序中,您可以使用< clrClass> 元素声明您的[ComVisible]类。版本控制现在变成部署详细信息。 MSDN操作方法在这里。请记住,它必须嵌入在客户端程序中,而不是您的[ComVisible]程序集。这往往是一个问题。


I need to deploy multiple versions of the same C# .NET project. The project output is a COM interop assembly to be used in a native application. The problem I'm having is that I have to deploy several versions of this assembly side-by-side but whatever I do doesn't seem to create different versions. Instead the versions override eachother.

I've tried changing the assembly GUID, tried changing the assembly version numbers, tried regenerating the assembly strong name key, tried changing the assembly title and description. I'd rather not have to change the GUID's or names for individual types in the assembly for versioning purposes.

How do I ensure these versions do not override eachother and that I can see and deploy them side-by-side?

Thanks in advance!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace InteropTest
{
    [Guid("...")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class Test
    {
        public Test()
        {
        }

        public string Version
        {
            get
            {
                return "1.0";
            }
        }
    }
}

解决方案

I'd rather not have to change the GUID's or names for individual types in the assembly for versioning purposes.

But that exactly what you have to do to prevent COM types from interfering with each other. The [Guid] is used to select the registry key in HKLM\Software\Classes\CLSID where the COM class is registered. Two distinct versions with the same Guid will overwrite each others keys. Otherwise known as DLL Hell. Changing the public interface requires a new Guid to ensure that clients that use the old one don't die with impossible to diagnose misbehavior. A rock-hard COM requirement.

Omitting the [Guid] attribute is very possible, you now leave it up to the CLR to generate one for you. Now the assembly attributes start to play a role, the guid value is auto-generated by a slick algorithm that includes the assembly name and the version as well as the set of methods on the interface and their arguments. Thus ensuring that any changes automagically produce a different guid. And, as expected and required, a different [AssemblyVersion] will generate a different [Guid].

Another approach, which is what I assumed you meant with 'side-by-side', is to not register the assembly but rely on a manifest instead. It must be embedded in the client program, you use the <clrClass> element to declare your [ComVisible] class. Versioning now becomes a deployment detail. The MSDN how-to is here. Keep in mind that it has to be embedded in the client program, not your [ComVisible] assembly. That tends to be a problem.

这篇关于COM互连体并排组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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