Global package installation using NuGet - visual-studio

Does NuGet support global package installation like NPM and Composer? If so, how do I do that? Also, how do I reference globally installed packages in my Visual Studio projects?

So learning from #Lance's tips, I went ahead and checked %userprofile%\.nuget\packages folder, and indeed it contains all the packages that I have downloaded in the past. Unfortunately though, Visual Studio (I'm using Community 2019) does not allow you to install any of these packages into a new project. The Browse page in NuGet Package Manager UI displays online results only from nuget.org.
But then I found another clue. In Visual Studio Tools > Options > NuGet Package Manager > Package Sources, you can add custom sources. So I went ahead and added my cache folder as an alternate source.
Note that there is a separate "Machine-wide package sources" entry too that cannot be modified. I checked that folder and it contains mostly Microsoft's own packages (one exception that I found there was NewtonSoft.json). I have no idea how this folder is different from the nuget cache folder and how I can download a package to this folder.
So far so good. The Package Manager now shows all previously downloaded packages from cache when I select this source from the drop down (sources dropdown is in top-right corner). I can then select a package and install it from local source instead of downloading it from the Internet.
Hope this helps someone down the line.

Related

Even with Nuget.exe 4.1.0 - Serilog already has a dependency defined for 'Microsoft.CSharp'

I know there's an answer for this question from 2016 but it's not working today. I have VS2013 with the latest CU installed.
My Nuget package source settings:
I want to install the nu-get package "Serilog.Sinks.MSSqlServer". First, I ensure nuget is up to date by navigating to the ".nuget" folder of the solution's folder and running "nuget update -self":
Unfortunately, I still get the error when trying to add the package:
If I try to update nuget from the "Extensions and Updates" page of VS then I get a 403 error as shown below:
The 403 does suggest a proxy issue but other packages can be installed to the same dev box ok. I just installed "Apache log4net" from the Manage NuGet Packages window - no problem
Any ideas of a work-around for this please?
This might be related to the fact that you now (with the new NuGet CLI tool version) need to use the new NuGet API.
from nuget.org
NuGet feed v3 (VS 2015 and later / NuGet v3.x and above): https://api.nuget.org/v3/index.json
NuGet feed v2 (VS 2013 and earlier / NuGet 2.x): https://www.nuget.org/api/v2
You can check (and edit) your NuGet Package Sources under Tools, Options, NuGet Package Manager, Package Sources.
#Rob Bowman, in response to your comment and looking at the screenshot of your Available package sources, try edit your default nuget.org to https://api.nuget.org/v3/index.json or add a new source and make sure they're both enabled. Maybe that'll do the trick.
Update: maybe manually updating the NuGet Package Manager (since updating it through Extensions and Updates is not working) solves the problem. NuGet Package Manager for Visual Studio 2013.
Going to Visual Studio menu Help, About should display the currently installed version of this extension (and others).
To fix this I had to:
logon to a PC not connected to the corporate proxy
download the latest version of the nuget package manager (VSIX) for VS2013 from https://marketplace.visualstudio.com/items?itemName=NuGetTeam.NuGetPackageManagerforVisualStudio2013
copy the VSIX to my corporate dev VM and install

TFS solution is downloaded along with the Nuget Packages but the references are missing?

I'm training 5 people on using Visual Studio. They've mapped their drives and have "downloaded" the solution from TFS which contains 10 projects. All located at the same depth in TFS folder structure. When the new folks download the solution there's one project that doesn't get the NUGET references even though the Package folder (created by NUGET) is at the same depth of the other 10 projects when viewed in TFS.
We know how to add these manually but is there a way to automatically have VS do it? Why would only one project lose it's reference with the Package Folder right there?
It seems you are still using MSBuild-Integrated package restore approach. If NuGet recognizes that the MSBuild-Integrated package restore approach is enabled for the solution, Automatic Package Restore is skipped.
You need to migrating MSBuild-Integrated solutions to use Automatic Package Restore, then the packages will be restored automatically.
In addition, you need to update you NuGet manager to the latest version in VS Tools--Extensions and Updates. And make sure Visual Studio is configured to 'Allow NuGet to download missing packages' and 'Automatically check for missing packages during build in Visual Studio' in VS Tools--Options--NuGet Package Mnager--General.
To Fix:
Unload all projects first, then right click and select edit project.
Find this line:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
Comment it out.
Reload all the projects and compile.
This applies to Nuget api version 2.
Note you may configure all projects for Nuget at the solution level.
The package manager for the solution presents a set of check boxes for every project along with the buttons (Install or Uninstall).

Visual Studio can't find Nuget packages from private Nuget Server

I am running NuGet.Server v2.8.60717.93, hosted on Azure. The server is running correctly, and I am able to see all the packages if I go to the following url:
https://***.azurewebsites.net/nuget/Packages
I am also able to publish new packages to the server using Nuget Package Explorer.
I added https://***.azurewebsites.net/nuget as a Package Source in Visual Studio. However it can't find any packages, it just says No items found.
To my understanding, Nuget will set /Packages as default package folder unless otherwise is specified. I even tried to set packagesPath to ~/Packages, still no luck.
What am I missing?
Also have this problem the RSS feed of package is showing in the browser if I navigate to https://***.azurewebsites.net/nuget/Packages but no items found in visual studio.

NuGet Package restore for website

I am trying to use NuGet Package Restore with VS2010 + Visual Sourcesafe. It is working partially for me.
Where this is coming from: NuGet not getting missing packages
My Solution2 has asp.net website[Project1 in above image] that has another nuget package installed. Now another developer opens the Solution2 via VS2010, the automatic restore works for Library projects in Solution1. It gets all missing packages for Library projects that is referenced in this Solution2 and I see them in Solution1/packages folder.
But for Website it says external dlls i.e. pacakages missing. The issue I think is because website doesn't have a .csproj file and so it doesn't know things needs to be restored.(http://nuget.codeplex.com/workitem/1663)
Making it work partially:
Added packages/repositories.config to website solution (What is a solution folder in visual studio)
Another developer goes to VSS and get that packages folder manually. Now when he builds the solution, the Package Manager Console prompts for restore i.e. has "Restore" button. On clicking it will bring the AjaxControlToolkit.
Questions:
- Is the above approach the only and best available for Websites?
When the developer clicks "Restore" button it brings packages for Library as well to Solution1/packages along with packages for nuget. Any reason why would it do that?
Any ideas on above issues?
Per you link, nuget doesn't support websites. If you really need to use Nuget, and let's face it, everyone does, then in my opinion the best approach is to switch your website over to a web application, at which point visual studio will create a csproj file for you, detailing the nuget packages that are contained in the project.
HTH
For adding Solution level "packages" folder with repositories.config to VS Solution Explorer, I created a Solution folder and added repositories.config.
That created packages folder in the SourceSafe when I checked-in the solution.
I also found someone pointing the same thing here.
Update: I think the newer nuget is restoring the packages. But one other trick for nuget to add the dll to the bin folder it to check-in the .refresh files for AjaxControlToolkit and its dependent packages.

Do Nuget packages need to be added by every developer who works on same VS project?

I've added some libraries to a VS 2010 solution using Nuget (RestSharp, Twilio, etc.). When I pull the same solution down to a new PC from TFS and try to build it, all the references to those assemblies are broken (error "namespace cannot be found..."). Is it necessary for each developer who works on this VS solution for the first time to independently install the same Nuget packages on their PCs?
Thanks,
Jim
As Andrew already have said it's all about the packages' location.
Either you have to check in the entire packages folder with all the packages, or each developer have to install the packages after first checking out. But there is a better way to do this, namely to use NuGet Package Restore - which will automatically install all missing packages when the project is built.
If you use package restore, you only need to check in the repositories.config into your VCS. With TFS you can cloak the entire packages folder except for the repositories.config, so that TFS doesn't annoy with pending checkins for new packages.
Also see this answer for guidance on how to use TFS + NuGet.
No, but you need to be sure the assemblies are all included in the same relative path so Visual Studio can find them. You can include the solution's nuget packages directories, which is where I think it stores a copy of the libraries to be referenced by the project(s).
Incidentally, including said diretories may be effectively the same as "installing the packages". If you include all the files that NuGet uses in its management of packages, NuGet will behave the same as if you had installed them. But you don't need to do the actual package install via NuGet for it to work... or even have NuGet installed in Visual Studio in the first place. It's just a matter of the proper files being where the Visual Studio project files expect them to be.

Resources