Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 views
in Technique[技术] by (71.8m points)

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

I have a setup project for a .NET Service Application which uses a .NET component which exposes a COM interface (COM callable wrapper / CCW). To get the component working on a target machine, it has to be registered with

regasm.exe /tlb /codebase component.dll

The /tlb switch to generate the typelib is mandatory in this case, otherwise I can't create objects from that assembly.

The question is, how can I configure my Visual Studio 2008 Setup-Project to register this assembly with a call to regasm /tlb ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...