Can NuGet distribute a COM dll?

2019-01-22 08:30发布

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

How would I setup the package?

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)?

1条回答
ら.Afraid
2楼-- · 2019-01-22 08:47

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

  • lib
    • MYCOMLib.dll
  • tools
    • mycom.dll
    • install.ps1

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

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 }

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.

查看更多
登录 后发表回答