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

查看:15
本文介绍了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.

    • MYCOMLib.dll
    • mycom.dll
    • 安装.ps1

    MYCOMLib.dll 是从 mycom.dll 生成的互操作 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 时是必需的.请参阅 无法嵌入互操作类型了解更多信息.

    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天全站免登陆