NuGet可以分配COM dll吗? [英] Can NuGet distribute a COM dll?

查看:128
本文介绍了NuGet可以分配COM dll吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用NuGet分发COM DLL?

Is it possible to use NuGet to distribute a COM DLL?

我如何设置程序包?

我想我可以把DLL放在Tools目录,然后运行安装后脚本注册库,但我不是很擅长PowerShell。

I'm thinking that I could put the DLL in the Tools directory, then run a post-install script to register the library, but I'm not very good at PowerShell.

有没有在线示例(如果可能)?

Are there any online examples of how to do this (if its possible)?

推荐答案

当我遇到类似问题时,我创建了一个具有以下结构的NuGet包。

When I faced a similar problem I created a NuGet package with the following structure.


  • lib

    • MYCOMLib.dll


    • mycom.dll

    • install.ps1

    MYCOMLib.dll是从mycom.dll生成的interop DLL,其中包含类型库导入器(tlbimp.exe)。
    只需使用命令:

    The MYCOMLib.dll is a interop DLL generated from the mycom.dll with the Type Library Importer (tlbimp.exe). This is simply done with the command :

    Tlbimp mycom.dll
    

    install.ps1包含以下代码:

    The install.ps1 contains the following code:

    param($installPath, $toolsPath, $package, $project)
    
    regsvr32 Join-Path $toolsPath '\mycom.dll' /s
    
    $project.Object.References | Where-Object { $_.Name -eq "MYCOMLib" } |  ForEach-Object { $_.EmbedInteropTypes = $false }
    

    COM dll并将引用上的EmbedInteropTypes属性设置为false,这在使用.NET 4时非常必要。请参见 Interop type can not be embedded for more information。

    What this script does is that it registers the COM dll and sets the EmbedInteropTypes property on the reference to false, which is necessary when using .NET 4. See Interop type cannot be embedded for more information.

    这篇关于NuGet可以分配COM dll吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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