How to register a COM shared as a NuGet Package in a Class Library (.NET Core)?

为君一笑 提交于 2020-01-05 22:52:49

问题


There are 4 projects:

  1. MyProject.Domain
  2. MyProject.Services.Contracts
  3. MyProject.Services.Acomba
  4. MyProject.Services.Acomba.Tests

The Acomba projects depends on a NuGet Package that I packed according to this SO Answer.

All of those projects are of type Class Library (.NET Core) and target:

  • NET451
  • NET452
  • NET461
  • NETSTANDARD1.5

Except for the test project which consists of a .NET Core App which target:

  • NETCOREAPP1.0

As the Getting started with xUnit.net (.NET Core / ASP.NET Core) webpage describes.

Whether I run the tests from the console or Visual Studio, it ends up with this error:

System.Runtime.InteropServices.COMException : Retrieving the COM class factory for component with CLSID {00000115-0000-000F-1000-000AC0BA1001} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLA SSNOTREG)).

This message makes it obvious that the COM library on which depends the Acomba projects is not registered on my local workstation, although I went through the installation process of the SDK shared as a COM library.

So my wish would be to run this install.ps1 Powershell Script from the NuGet Package or to get it ran automatically on project compile. Unfortunately, this script is nowhere to be found, neither are the packages referenced in my projects, since their compiled on the fly with Roslyn.

How to register a COM shared as such through a Nuget Package in a Class Library (.NET Core)?

UPDATE

Based on this post: Creating a Nuget package that will install files relative to the solution, the install.ps1 script contained in the tools folder of the NuGet Package should be run upon Package installation. So I guess this might be something about the script itself that doesn't really work out.

Is there anything wrong with this script?

I don't know much about Powershell, hence my question.

install.ps1

param( $installPath, $toolsPath, $package, $project )

regsvr32 Join-Path $toolsPath '\AcoSDK.dll' /s

$project.Object.References 
    | Where-Object { $_.Name -eq "Acomba.SDK" } 
    | ForEach-Object { $_.EmbedInteropTypes = $false }

UPDATE

I noticed whilst registering the DLL using regsvr32.exe that there was an error. It turned out to require elevated permissions to register the DLL. So, I tried running VS as an admin, and it changed nothing. The same error message displays. =(

Can it be because I run tests using a NETCOREAPP1.0 (test project) with a NETSTANDARD1.5 library that it fails or?

To be noticed that whenever I use a "regular" Class Library, it works flawlessly. I just don't understand the problem...

UPDATE

The CLSID is found in the Windows Registry using RegEdit.exe. So it is registered.

What could cause the project not to find the registration or whatever it is?

来源:https://stackoverflow.com/questions/37365362/how-to-register-a-com-shared-as-a-nuget-package-in-a-class-library-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!