This last Sprint, I spent 3 or 4 days trying to get an internal NuGet Package updated, the version bumped, and get it published to Azure Artifacts. Then get a project that relied on this project updated.
Let me start by saying IT DID NOT GO AS PLANNED.
I learned a bit about NuGet in the process that I would like to share for those, who like me, are new to having to working with their own (read “Someone else’s”) NuGet package that they publish.
NuGet Packages Get Stored in 2 Places
There are two places that NuGet packages get stored. The first is usually somewhere like C:/Users/<username/.nuget if you are using Windows. This location is very important if you happen to be working with packages and want to test your own version without bumping the version number. You can just come here and replace the file if that is what you want to do.
The trick to this treat is that Visual Studio caches your NuGet files in memory (or at least that is my current theory). So make sure that you either Restore the package via the NuGet package manager or restart Visual Studio if you want to save yourself 20-40 minutes of confusion.
There are two ways to pack NuGet
You can use either the dotnet CLI or use a nuget.exe package. Apparently there is some weirdness with support that is going on between these two so some more research on what will work best for your scenario may help.
You can put multiple Dll or NuGet files into One Master NuGet
I initially ran into technical issues with versioning with my project with 50+ cross dependiencied NuGet packages, so one of my co-workers suggested making one NuGet Package to rule them all. I ended up finding this link and created a <ProjectName>.Shared.All.csproj file using this technique, but I found out that you also have to include each Package Reference from every other project in order to get it to work correctly (this is not an ideal solution but this is not really a fully baked feature in NuGet or DotNet right now. Any other method that we tried did not work correctly.
When In Doubt, Start Over or Get Help
NuGet seems to be very finicky. So I have a few suggestions if you are about to pull your hair out because things aren’t working like you think they should.
- If you are converting over from a multi-Nuget to single NuGet setup, don’t do String Replace, use the NuGet Package Manager to install and uninstall. ( I had so many problems with packages not loading correctly and NuGet seems finicky in VS 2019)
- Blow Away Your Repo, Local Nuget Files, and Try again if nothing makes sense.
- Get Someone else to try it on their machine, maybe it just doesn’t work on yours 🙂
- Get familiar with the difference between Package.config and PackageReference
Some Tools and Links To Help
Here are some of the tools that hat might help you in your quest to slay the mighty NuGet
NuGet Package Explorer – Manually Create and Inspect NuGet Packages
Nugetizer 3000 – Not sure if it is still helpful but maybe it will help you out