I want to use a nuget package as a dependency for a personal project of mine, but the contents of the package that I want to use are not included in the latest release. It is a project that only gets releases about every year or two. There was some essential code added to the Github repo of the nuget package in question recently and really want to use the new code.
Btw, I know that this isn't recommended because using bleeding edge and unfinished code is a recipe for bugs and maybe even security vulnerabilities. This is an exception though and I am using this code privately and at my own risk.
So in order to get the bleeding edge nuget code as a dependency in a personal project of mine, I cloned nuget project's repo, renamed the repo and ran dotnet pack --output nupkgs
. This created a .nupkgs
file and I uploaded that to my nuget profile. I made my nuget upload unlisted because, again, this is private/personal use code at my own risk and I don't want anyone else using it (and possibly running into security issues).
So back to my own personal project where I want to add this bleeding edge self uploaded nuget dependency... I ran this command dotnet add package <MY UNLISTED NUGET PACKAGE> --prerelease
and I got this in my terminal:
Determining projects to restore...
Writing /var/folders/path/to/file/tmp<RAND NUM HERE>.tmp
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/local/share/dotnet/sdk/6.0.401/trustedroots/codesignctl.pem'.
info : Adding PackageReference for package '<MY UNLISTED NUGET PACKAGE>' into project '/Users/path/to/<myproject>/<myproject>.csproj'.
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/<MY UNLISTED NUGET PACKAGE>/index.json
error: There are no versions available for the package '<MY UNLISTED NUGET PACKAGE>'.
So how do I add my unlisted nuget package to my personal project's dependencies?
CodePudding user response:
If you only need that package locally, you can copy the created nuget package to a folder of your choice and add the path to that folder to your nuget.config.
This can also be done in VisualStudio in the Options -> NuGet Package Manager -> Package Sources.
But beware this dialog is a little wonky. First click on the green plus in the top right corner and do not forget to click on update after adding the folder to the "Source" line.