upstream packages not showing up in VSTS Package Management - nuget

I've configured the Package Management extension in my VSTS project and added nuget.org as an upstream source.
I've configured my Visual Studio project to use my VSTS feed as the only package source.
I've installed a nuget package from nuget.org via my VSTS feed using Install-Package on the Package Manager Console. I'm expecting the package to then show up in my VSTS feed, but it's not.
Are my expectations wrong, or am I missing a step?

I had previously installed this nuget package so it was in my local nuget cache. I cleared the local nuget cache (Tools->NuGet Package Manager->Package Manager Settings->General->Clear All NuGet Cache(s)) and re-installed the package, and then saw it pull through my VSTS feed and cache it there.

Related

Managing nuget updates in local nuget repository

Let's suppose there is a .NET Core project that has a reference to a nuget package say nugetD. That nuget package in turn have references to 3 other nuget packages say nugetA, nugetB and nugetC.
The nuget packages are managed locally in a local nuget repository.
When the nuget package nugetD is modified and new version is pushed into the nuget repository then Visual Studio will alert us in the "Manage Nuget Packages" window saying there are updates for that nugetD.
Is there a way to alert us using any tool if let's suppose any of the underlying dependent packages (for nugetD): nugetA, nugetB and nugetC were modified and new versions were pushed to the local nuget repository?
How can the parent nuget package know or track that if they have any dependent child nuget references were modified and that the parent nuget package needs to update to the latest dependent packages?

Ensuring a NuGet package can only be installed from a specific feed

I have an Azure Pipelines job setup to authenticate to a private NuGet feed in Azure Artifacts, and then build my .NET project that relies on a NuGet package in the feed. However, my private package is a pretty common name. How can I ensure that it only installs that specific package from my private feed, and doesn't try to fallback to the NuGet general gallery? I do not want it to pull in an incorrect package that has the same name and version name as my private package.
Once you configure multiple sources/feeds, NuGet will look for a package in all these sources together with no guarantee of where the package will be downloaded from. However, you could make the AzDo artifacts feed as the only configured feed and then upstream other sources from it. This way NuGet will get all packages from the configured AzDo artifacts source and AzDo artifacts will source other packages not available with it from the upstreamed sources in the order defined. More info can be found here: https://learn.microsoft.com/en-us/azure/devops/artifacts/concepts/upstream-sources?view=azure-devops

How to publish a nuget package privately using Nuget Gallery

I have created a nuget package and I want to share it with my team using Nuget Gallery.
I need to publish the nuget package privately.
So I have managed to build the Nuget Gallery from Nuget Gallery build steps
When I run the build, Google Chrome shows up with "localhost" website address showing Nuget Gallery.
1) How do I add the nuget package that I have created recently to the local Nuget Gallery?
2) How do I publish the Nuget Gallery and share with my team after I have managed to add nuget package in that gallery?
Thanks
You can also create your own Nuget server running in your local network by using the Microsoft NuGet.Server available in nuget.org ;-)
If you haven't seen it already, have a look at the docs on hosting a private nuget feed. TeamCity has a NuGet feed built-in, so you may not need to host a NuGetGallery yourself.
Depending on where/how you host your private feed, it might have a UI that you can use to upload packages (such as the NuGet Gallery). But if you're creating packages as part of a CI pipeline, it's probably easier to just use nuget push and use the -Source parameter to specify which source you want to push to, assuming your nuget.config has more than once source defined.

NuGet package restore tries to retrieve in all configured NuGet sources

While installing the NuGet packages from the NuGet package manage, having configured multiple NuGet package sources in VS2017, the NuGet client tries to retrieve the package in all the configured NuGet sources and returns messages like "Not Found".
I have configured the below NuGet sources in my NuGet.Config,
I have tried to restore the Newtonsoft.Json NuGet package from the command prompt by using the nuget restore command. The NuGet client will try to retrieve the Newtonsoft.Json NuGet package from my custom NuGet feed, which does not contain the Newtonsoft.Json package and returns a NotFound message in the output:
However the package is restored perfectly without issues. But why does the package manager search all the sources which are configured and prints not found errors even it found it in the first NuGet source?
Why does the NuGet client try to retrieve in all configures sources? Is this a bug from NuGet? I am using Visual Studio 2017 (15.4) and NuGet package Manager (4.4.0).
No, it's not a bug.
When the NuGet client is doing a restore and sees you have a dependency on some package, it has no way of knowing which feed the package exists in. In the past, the NuGet client would query each source in order, but at some point it was changed to query all sources concurrently and use the first successful response.
There are also several scenarios where you would want to get a package that is available on nuget.org, from a source other than nuget.org. One example is you might have a private feed with commonly used packages on the same network as your build servers, so that package restore is as quick as possible and more resilient to network outages.

Force update TeamCity NuGet feed

When we push a new version of a NuGet package to our NuGet feed the package will appear in the file system on the NuGet server. The NuGet feed API and in visual studio, however only update roughly every hour so we may have to wait up to an hour for new packages to show. Is there a way to force update the NuGet feed to accurately depict what is in the file system?
I've encountered very similar issue, after publishing new package version to private TeamCity NuGet feed it hasn't appeared in visual studio immediately. It took time to update.
However, new package version itself was available via request:
http://<teamcityserver>/guestAuth/app/nuget/v1/FeedService.svc/Packages(Id='<packageId>',Version='<newPackageVersion>')
For example:
http://test:8111/guestAuth/app/nuget/v1/FeedService.svc/Packages(Id='TestPackage',Version='1.0.1')
I resolved it by cleaning local NuGet cache
via
Tools → Options →  NuGet Package Manager → General → Clear all NuGet cache(s)
or
dotnet nuget locals all --clear
See related answer:
https://stackoverflow.com/a/42665980/2793919