Nuget Package Installation is Not Adding References To Project - c#

I have published a package in Nuget few years ago. From time to time, I was updating it with new versions and all was ok until now.
Few days ago I've published an update to Nuget and when I've updated my package, it was installed successfully but it never added any references to my project.
I've even started from blank console applications and tried to add my package. Same problem.
You can try. This is a package
https://www.nuget.org/packages/63BITS-Libraries/
This is how I built my package
Any ideas?

If you download your nuget package, and unzip it (yep its just a zip file). You will find that your DLL is not in the lib directory.
Typically, inside a nuget package, any dlls need to be in lib/<FrameworkVersion>
For example if your DLL targeted netstandard1.6 then in the nuget package the path to your dll would be lib/netstandard1.6/SixtyThreeBits.Libraries.dll
In your package, your dll is in SixtyThreeBitsLibraries/SixtyThreeBits.Libraries.dll

Related

Can't install or update any nuget packages in my project in vs2017

When I used vs2015, packages were added to a packages folder in my solution and a package.config file was added and also reference includes in the csproj file. But since I use vs2017 I'm not able to install or update any nuget packages, although the packages are downloaded and unzipped in this location:
C:\Users\user.nuget\packages:
packages
I tried both Manage Nuget Packages and Package Manager Console, but I get the errors "Install failed. Rolling back." and "Could not add reference, dll not registered." I tried installing webview2, newtonsoft json and restsharp but get the same errors.
Here's the output:
output packetmanager
So how can I download and unzip a package into a package folder in my solution and install it in my project ?

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:
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".
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:
placing the dll at the root
placing the dll inside a "lib" folder
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!

Can I use the DLLs included in the nuget package

I used Nuget package explorer to pack some third party DLLs into one package and published to my nuget server, many of my projects need refer to those third party DLLs and I don't want to add DLL references over and over again. With nuget I only need to install one package.
But after installing that package, i can see those DLLs in the packages folder, but I cannot use classes in those DLLs.
Is that possible to use classes in the DLLs of that nuget package?

Unnecessary folders from NuGet packages

My c# app target framework is 4.6.2
I downloaded from NuGet some packages, my question:
when I open my app in file explorer, under packages\somepackage\lib I have this:
do I really need net 40 and net45 folders?
can I delete that? how do I know what is unnecessary?
Reason why NuGet keep the folders
Nuget uses two different methods to manage packages of every project:
packages.config
PackageReference
packages.config is only used for old project files which cannot import and reference NuGet packages automatically. NuGet will change the *.csproj file to add the references. Because it changes the code which is under version control and cannot use an absolute path, so it should put the NuGet package cache folders in every solution. In this case, NuGet might have the ability to remove the useless folders. But this is the behavior of legacy NuGet version (version 2.x). NuGet doesn't want to fix a legacy behavior.
PackageReference is the new behavior of NuGet references. NuGet put all the NuGet cache in a common folder so that it will not take too much disk space by the same NuGet packages. In this case, NuGet doesn't know every lib version on your whole computer projects, so it can't remove the useless version folders.
Conclusion: NuGet doesn't know whether it is safe to remove them in PacakgeReference and doesn't want to remove them in packages.config.
Upgrade packages.config to PackageReference
UPDATE:
From VisualStudio 2017 version 15.7 there is an integrated feature that allows you to do this upgrade without using third party tools Migrate from packages.config to PackageReference
In Solution Explorer, right-click on the References node or the packages.config file and select Migrate packages.config to PackageReference...
You can try a Visual Studio extension NuGet PackageReference Upgrader to upgrade your packages.config to PackageReference so that it will not store libs in every solution folders to eat up your disk space.
P.s.
NuGet take me nearly 10GB on my C:\ .

Must the DLL be in the lib folder in a nuget package

I tried to download the latest version of this nuget:
JSON Web Token Handler For the Microsoft .Net Framework 4.5 3.0.1
but its not installing correctly in my project.
In my Visual Studio solution, I looked in the folder:
\packages\System.IdentityModel.Tokens.Jwt.3.0.1\
and the DLLs exist, but they are not within the lib folder. They are in the package's root.
When I try to install it in my VS project, it says its been installed, but no project references are added.
I think its broken. Can anyone confirm that a nuget must have a lib folder and the DLLs must be within the lib folder.
Yes, I duplicated the folder structure of the previous package (version 3.0.0) and got it working. I left two messages with the author a week ago.
We just pushed a new version out, 3.0.2, that fixes this issue. Please try to update the NuGet and let me know if the issue is resolved.

Categories

Resources