简体   繁体   中英

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. 在此处输入图像描述 在此处输入图像描述

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在此处输入图像描述
    2. placing the dll inside a "lib" folder在此处输入图像描述
    3. placing the dll inside a "lib/netstandard2.0" folder在此处输入图像描述

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. 在此处输入图像描述 在此处输入图像描述

Has anyone had any success doing something like this before?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM