4

I'm relatively new that whole NuGet package stuff and currently I'm struggling a bit with including a referenced COM DLL.

I have a little Utilities library for Autodesk Inventor. So I included the COM reference.

References

Now I want Visual Studio to automatically create the NuGet package

enter image description here

So every time I build my project, Visual Studio recreates the .nuspec file and generates the package but unfortunately without adding the referenced Inventor DLL to the lib folder inside the NuGet package. I read a lot about adding it manually or editing the .nuspec file, but is there a more simple solution where Visual Studio will do this part for me?

I'm working with VS2017

Thanks in advance

Ipsit Gaur
  • 2,872
  • 1
  • 23
  • 38
fm611
  • 119
  • 12
  • Building a nuget package for a library that has a dependency on COM server is not a very good idea. You can't do anything to deploy the server, you can't be sure what version the user has installed. And no, you shouldn't try to deploy the interop library, the "Embed Interop Types" feature makes it unnecessary. You forgot to tell us what goes wrong, but clearly the user needs to have the *exact* same version of the server installed and probably needs to add a reference to the interop library as well if you expose any of the interop types in your public members. – Hans Passant Jun 25 '18 at 09:54
  • Thanks for your help. I understand what you mean but that brings me back to the root question: Is there a "best practice" way to store a library with common functions I need over and over again for different projects? Or is the right way back to basic and just having an classic dll file? – fm611 Jun 25 '18 at 18:23

1 Answers1

4

I read a lot about adding it manually or editing the .nuspec file, but is there a more simple solution where Visual Studio will do this part for me?

Just as Hans said, we do not recommend you build a nuget package for a library that has a dependency on COM server. But if you insist on it, I am afraid you have to do it manually or editing the .nuspec file.

That because its added with <COMReference> not <PackageReference>, we could not use Controlling dependency assets to add those dll file into the NuGet package, and there is no such option on the Visual Studio that we could include that COM dll to the nuget package.

So, to resolve this issue, we have to do it with manually or editing the .nuspec file, you can check following thread for some more details:

Create nuget package from dlls

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • I'm in a similar situation. I have a 3rd party COM library referenced from a .NET Standard 2.0 library project. No problem compiling locally, but I'm trying to figure out what I need to do to get it to compile on our CI build server. Can this be done using the technique you mentioned to manually include the COM dll in the NuGet package? Or is the only option to manually install the COM library on the build server and not rely on NuGet at all for COM dependencies? – Ifligus May 08 '20 at 14:18