Nuget List CLI command is showing deleted packages - c#

I am on a Mac using .net core 2.0 and Jetbrains Rider. I have a network folder where I publish my private nuget packages.
nuget push <packagePath> -source <localNugetPath>
I delete a package from the local folder.
nuget delete <packageID> <packageVersion> [options]
This deleted the nuget package from the network folder but yet it still shows in Rider as an options.
nuget list [search terms] [options]
The above nuget list command will also show the package. How do I permanently get ride of the package?

NuGet does not allow for package delete and instead relies on unlisting the packages. This means:
This unlisted version is not shown in new searches and hence will not get auto resolved to, in new projects.
However, existing projects that have references to this unlisted version continue to work as before. (And that's one of the reasons for not allowing delete - so that existing projects do not break)
The package can shows because it cached. To clean all cache use command:
nuget locals all -clear

Related

What is the link between a nuget package and its source?

In my company, NuGet packages are coming from different sources:
nuget.org (http://api.nuget.org/v3/index.json)
Microsoft Visual Studio Offline Packages (C:\Program files (x86)...\NuGetPackages)
Company_NuGetFeet#local (https://Company.pkgs.visualstudio.com/_packages/.../nuget/v2)
Supervision (some http://10.1.3.xxx/nuget site)
When I start up Visual Studio, I get logged in automatically (at the above right corner, I can see my login settings).
I have access to some NuGet packages and there are some where I don't have access to:
Company.Something.UA : OK
ControlzEx : OK
DevExpress.Chartsv18.2_Core : NOK
I have been doing NuGet restore in lots of ways: normal commandline, developer prompt, using the standard NuGet.exe, using the latest NuGet.exe, from within the company network, from outside the company network, ..., it does not make any difference.
In order to pinpoint the problem, I was thinking of restoring a single NuGet package, which should come from one specific package source, but what is that source?
When checking the properties of NuGet packages (being OK or not), the package source is not mentioned.
So I would like to do:
NuGet.exe restore DevExpress.Chartsv18.2_Core DevExpress..._Core_Package_Source
How can I do that?
How can I know from which package source I need to download a specific NuGet package?
There is no link. Package restore searches all sources in nuget.config (either system-defined or project-defined) for a package, in the order those sources are specified, and installs the first matching package it finds.
What you're really asking is "how do I install a package from a specific source", and you can do that with dotnet restore. Note that NuGet.exe is legacy and deprecated; its package restore functionality is integrated into the dotnet tool and improved there.
> dotnet restore MyPackage -s NugetSourceName
There is no way to know which source a package is available in without browsing it, but as stated above it shouldn't matter; package restore will figure it out.
Now (with .NET 6 tooling) you do have a way to pin packages (patterns) to specific package sources. The feature is called "Package Source Mapping":
https://learn.microsoft.com/en-us/nuget/consume-packages/package-source-mapping
https://www.youtube.com/watch?v=G6P38Dn69Ro
https://devblogs.microsoft.com/nuget/introducing-package-source-mapping/

Delete NuGet packages from Visual Studio Online Package Feed instead of Unlist

Is it possible to delete NuGet packages from a Visual Studio Online package feed?
I've setup CI on Visual Studio Online using the Build Tasks for a dotnet core project.
One of the steps is to pack all the projects in the solution as NuGet packages and push these to the package feed.
The build is working fine, however in my first attempt in the pack and push build steps I used a **/.csproj wildcard instead of src/**/.csproj. So it packed and pushed all my test projects too that were under tests/**.
I'd like to delete these packages from the feed. The only option I could find in the UI was to unlist the packages. But the packages still exist after this operation.
I also tried to delete the packages through the CLI: nuget delete. But it just does the same as unlist.
Has anyone been able to delete their packages?
Yes, this is possible out-of-the-box with VSTS' Package Management. Note that there is a difference between unlisting and deleting, which I'll elaborate on further.
The TL;DR story for deleting existing packages from VSTS Package Management is that you must be the 'owner' of a package OR have a 'Project Admin'-like role in order to delete it. To unlist a package, you only require the 'contributor' role. For both options, simply go the package details in VSTS and select the appropriate option from the menu under the ellipses:
Now for some background info which might be useful. There is some official documentation available on visualstudio.com:
There are two options available to remove a version of a NuGet package from a feed.
Unlist: unlisting a version of a package modifies how the package appears in NuGet clients (see the NuGet docs for a full description of how unlist works). Unlisting a version can help you prevent new usage of it without breaking dependent projects and builds.
Delete: Deleting a version of a package makes it permanently unavailable for install or restore.
Unlist and delete both respect feed immutability. Once you publish a particular version of a package to a feed, that version number is permanently reserved. You cannot upload a newer revision package with that same version number, or delete it and upload a new package at the same version.
The important part here is "feed immutability", which according to the canon, translates to:
Once you publish a particular version of a package to a feed, that version number is permanently reserved. You cannot upload a newer revision package with that same version number, or delete it and upload a new package at the same version.
The documentation also confirms, as a footnote at the bottom, what you already discovered about nuget.exe:
Currently, NuGet.exe can only unlist packages; Team Services and TFS interpret nuget.exe delete as an unlist operation to be consistent with NuGet.org. To delete a package, you must use either the REST APIs or the web interface.
Doing it programatically should therefor either be done through the REST API or the VSTS admin section, as described above. NuGet.exe can only be used for unlisting - not deleting.
With all of that taken into consideration, with VSTS you can delete packages but - as always - think twice before you do so. Remember the LeftPad debacle? ;)

After clone of web site project nuget restores packages but references are not found VS 2015

We have moved a legacy web site to git in TFS, and anytime the project is cloned nugget restores the packages per the package.config, and adds them to the packages folder. The subsequent build fails due to not being able to find the assemblies added through the nuget restore.
If you do a update-package -reinstall and the project builds successfully. Is this expected behavior or do I have a setup issue? The previous repo had the packages being checked in to eliminate this issue but I'd like to avoid that.
Is this expected behavior or do I have a setup issue?
Yes, this is expected behavior for NuGet, so do not worry that it is a setup problem.
NuGet Restore only restores files in the packages directory (\packages folder ), but does not restore files inside your project or otherwise modify your project. For example, if a package has added some reference DLLs or other files in your project, if you delete any of these files, they will not be re-added when restoring this package. This may cause the your project to not be able to find the missing dependencies when building.
Besides, the expected result is that the references should be used normally without broken after restore packages. In this case, we will not need to spend extra time using update-package -reinstall command line to uninstall and reinstall packages.
So use the "Update-Package -reinstall" command to force reinstall the package references and content files into project in order to resolve those references that were broken after packages restore.

how to do 'check in' to code that uses Nuget package

i want to do 'check in' to code uses Nuget package.
what is the the best way to do it?
Do i need to do 'check in' to the package folder?
Is there any way to put the dll's (nuget's dlls) in GAC and add them public key token?
My solution is written in c# .net framework 4.5. TFS version - 2015
thanks!
You should not check in NuGet packages into TFS Version Control. As one of the advantages of using NuGet is that you can use it to avoid checking in binaries to your version control system.
In VS, you can enable package restore:
In TFS, you need to restore NuGet packages during TFS build process by adding a "Nuget Package Restore" task to your build, and the required packages will be downloaded.
More information, refer to this article: https://docs.nuget.org/ndocs/consume-packages/package-restore

NuGet - managing and removing multi version packages in single solution

SCENARIO
One VS solution with n projects. Project A references package Y v1, Project B references package Y v2. It is now not possible to update all references to package Y for all projects in the solution using the NuGet package manage dialog at the solution level, it is only possible to do this when all projects reference the same version of package Y. Not a big deal for only two projects, but I'm dealing with lots of projects that through poor package management are referencing many package versions when they should all reference the same version.
Before I spend the afternoon writing a console app. to auto update all package.config files for a solution so that each referenced package is only referenced via it's latest version (latest referenced, not the very latest, with exceptions/caveats etc)....is there a tool/method for doing this already? Or some other approach I am unaware of?
You can accomplish this in the Nuget Package Manager for Solution (To find the menu, right-click on the solution or go in Tools->Library Package Manager). The Update tab in this dialog will propose to update for multiple projects where the update is applicable. The same applies with uninstall from the Installed tab.
Or with the solution opened, open the NuGet Console, run "Update-Package" to update all packages for all projects. It can also work to update specific packages/projects :
Update-Package [-Id] <string> [-IgnoreDependencies] [-ProjectName <string>] [-Version <string>] [-Safe] [-Source <string>] [-IncludePrerelease]
It will find the same updates than in the dialog, just make sure the right feed (or "All") is selected in "Package Source:" dropdown.
example:
PM> install-package NUnit -version 2.5.9.10348 -ProjectName ProjectA
Successfully installed 'NUnit 2.5.9.10348'.
Successfully added 'NUnit 2.5.9.10348' to ProjectA.
PM> install-package NUnit -version 2.5.10.11092 -ProjectName ProjectB
Successfully installed 'NUnit 2.5.10.11092'.
Successfully added 'NUnit 2.5.10.11092' to ProjectB.
PM> update-package
Updating 'NUnit' from version '2.5.9.10348' to '2.6.0.12054' in project 'ProjectA'.
Successfully removed 'NUnit 2.5.9.10348' from ProjectA.
Successfully installed 'NUnit 2.6.0.12054'.
Successfully added 'NUnit 2.6.0.12054' to ProjectA.
Successfully uninstalled 'NUnit 2.5.9.10348'.
Updating 'NUnit' from version '2.5.10.11092' to '2.6.0.12054' in project 'ProjectB'.
Successfully removed 'NUnit 2.5.10.11092' from ProjectB.
Successfully added 'NUnit 2.6.0.12054' to ProjectB.
Successfully uninstalled 'NUnit 2.5.10.11092'.
Firstly, only changing the xml files is not enough for NuGet to change the references. In fact, sometimes you get errors when you modify packages.config files by hand. package manager console has the ability to update all packages in the solution; you can simply call "Get-Project -All | Update-Package" command.
And secondly, before calling this command, make sure you have proper package sources available.

Categories

Resources