如何通过Visual Studio 2008安装程序项目中的重注注册.NET CCW [英] How to register a .NET CCW with regasm from a Visual Studio 2008 Setup project
问题描述
我有一个.NET服务应用程序的安装项目,该项目使用一个.NET组件,该组件公开一个COM接口(COM可调用包装器/CCW). 要使组件在目标计算机上工作,必须向
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 a target machine, it has to be registered with
regasm.exe/tlb/codebase component.dll
regasm.exe /tlb /codebase component.dll
在这种情况下,必须使用/tlb开关来生成typelib,否则我无法从该程序集中创建对象.
The /tlb switch to generate the typelib is mandatory in this case, otherwise i can't create objects from that assembly.
问题是,如何配置我的Visual Studio 2008安装项目以通过调用regasm/tlb来注册此程序集?
The question is, how can i configure my Visual Studio 2008 Setup-Project to register this assembly with a call to regasm /tlb ?
推荐答案
通过使用System.Runtime.InteropServices.RegistrationServices代替,您可以丢失对regasm.exe的手动调用:
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.
这篇关于如何通过Visual Studio 2008安装程序项目中的重注注册.NET CCW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!