How to register a .NET CCW with regasm from a Visual Studio 2008 Setup project

前端 未结 5 640
Happy的楠姐
Happy的楠姐 2020-12-10 07:41

I have a setup project for a .NET Service Application which uses a .NET component wich exposes a COM interface (COM callable wrapper / CCW). To get the component working on

5条回答
  •  盖世英雄少女心
    2020-12-10 08:25

    You can lose the manual call to regasm.exe by using System.Runtime.InteropServices.RegistrationServices instead:

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Install(IDictionary stateSaver)
    {
    base.Install(stateSaver);
    
    RegistrationServices regsrv = new RegistrationServices();
    if (!regsrv.RegisterAssembly(GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
    {
        throw new InstallException("Failed to register for COM Interop.");
    }
    
    }
    
    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Uninstall(IDictionary savedState)
    {
    base.Uninstall(savedState);
    
    RegistrationServices regsrv = new RegistrationServices();
    if (!regsrv.UnregisterAssembly(GetType().Assembly))
    {
        throw new InstallException("Failed to unregister for COM Interop.");
    }
    }
    

    This also unregisters the library upon uninstall.

提交回复
热议问题