Search code examples
c#dllnuget.net-standard

Can you create a NuGet package for just an assembly


Background: I am using Visual Studio 2019 Professional Version 16.11.15, and NuGet Package Manager 5.11. I was provided some 3rd party assemblies to use for my .NET Standard 2.0 class library. These dlls were installed locally on my machine by an installer. I added them to my project via "Add Project Reference". Here's a screenshot of them working. enter image description here enter image description here

Goal: Create a NuGet package for my .NET Standard 2.0 class library to be used internally by our dev team. It should encapsulate these 3rd party dlls as part of it. But I keep running into dead ends.

Important note: Xceed does not host these .NET Standard assembly versions on nuget.org, purposefully making my life difficult it seems...

I have tried:

  1. Using the "Generate NuGet package on build" in the Package section of the project properties. This option does not attach the 3rd party assemblies with it. This includes setting the Copy Local option to "Yes".

  2. Adding these 3rd party dlls to their own NuGet packages via NuGet Package explorer following this answer. I tried several different flavors of folder structures:

    1. placing the dll at the root enter image description here
    2. placing the dll inside a "lib" folder enter image description here
    3. placing the dll inside a "lib/netstandard2.0" folder enter image description here

None of these options worked when adding the NuGet packages to my project. The references to the assembly namespace weren't resolving in the code. enter image description here enter image description here

Has anyone had any success doing something like this before?


Solution

  • It turns out I was running into the problem of the NuGet packages not refreshing when updating it. I followed this the first part of this answer to solve that.

    When using the folder structure "lib/" inside the NuGet package, I was running into this warning:

    Warning NU1701  Package 'Xceed.Document.NETStandard 2.3.2' was restored using 
    '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, 
    .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, 
    .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' 
    instead of the project target framework '.NETStandard,Version=v2.0'. 
    This package may not be fully compatible with your project.
    

    Once I updated to use "lib/netstandard2.0/" inside the NuGet package, I was able to add the NuGet packages to my library successfully and compile. Great success!