NuGet Package Manager not seeing one package as already updated - visual-studio

I want to know how I can debug a NuGet package not properly showing as updated. In my specific case the package for jQuery.Validation is (the only one left) in the "Update" list, but hitting the update button does nothing. Here's the dialog for Managing NuGet Packages for my solution:
Hitting the "Update" button will give an additional popup:
As you can see everything seems slightly grayed out (what does that mean?). Hitting "Ok" just brings me back to the other dialog.
The main problem is that I don't know how to debug this sort of problem. I've tried doing the following:
Opening the Package Manager Console to see if it logs any trouble. No dice.
Checking the jquery.validate.min.js file, which mentions version 1.13.1, which is in fact the one mentioned in the dialog as the newest version.
Checking the packages.config file, which also mentions my solution includes version 1.13.1.
Restarting Visual Studio. No dice.
Remove the package. Re-add the package. No dice (not even after restarting Visual Studio again).
Is this just a bug in the Package Manager or the package? How can I further debug the root cause of this problem?
I'm using Visual Studio 2012, have updated the product as well as all extensions (including the NuGet package manager). The solution was originally based on an MVC 2 template, and has been updated for each major MVC release (currently up to MVC 5). Only this particular package is giving trouble, I've succesfully updated 10+ other packages just before this one.

This can happen if you have an old NuGet package left in the packages directory.
When managing packages for the solution the NuGet dialog will show updates for all packages that are in the packages directory even if they are not installed into any projects. If you manage the packages for the project on its own the NuGet dialog would not show any package updates as being available.
So the workaround is to remove the unwanted NuGet package from the packages directory.

Related

Reference hell accessing .netstandard with framework VS2019 preview

I can get my .net standard 2.0 package working in a .net framework 4.7.2 dll if I do the following steps
In my standard project VS2019 61.4.4 right click the project and select pack to create the .nupkg
Then I set up a nuget package source for the package
In my framework project I install nuget package
I get the following dialog
I choose PackageReference in project file
I answer yes to accept licensing
Then I can see the following
And I can get my project working.
However on a different machine running VS2019 16.5.0 Preview 2.0, I do not get the dialog asking me to choose the package manager format.
Instead the references look like
and I can not get my project working.
[Update]
After following Lance's link to migrate packages.config to PackageReference
The project looks like
I was able to remove the unwanted packages by right clicking references and choosing Remove Unused References
The program worked!
Go Tools=>Nuget Package Manager =>General => Package Management You can control the behavior by Allow format selection on first package install. Enable the checkbox and restart VS, this change will take effect.
And note the dialog only appears when we install first package in current project. So if you create a new project and install package, it will appear. And since you once installed packages in that project, the dialog won't appear in WindowsFormApp2 any more.
(But you can easily migrate packages.config to PackageReference, see this).

How to restore NuGet packages for vs2015 project

I just built a new PC, installed my dev tools, connected to TFS and downloaded my project. Now most of my references are broken to EF, jQuery, etc.
The packages folder is missing all the .dlls, if I try to use NuGet restore nothing happens. If I use NuGet manager for Solution there is no "force" reinstall option.
NuGet seems to be more a hindrance than a help.
You can run "Update-Package -reinstall" command from Package Manager Console in VS to force reinstall all the packages.
Package authors often need to reinstall the same version of package
they are developing to test the behavior. The command Install-Package
does not provide ‘-force’ option, that could forcefully reinstall a
package. So, Update-Package -reinstall is added to meet that
requirement.
I've had that same issue plenty of times when I need to re-download code after getting a new PC. Here's what worked for me:
Download the project from TFS (or in your case SVN).
Delete the "packages" folder
Make sure the "Package Manager Console" is enabled (Tools -> NuGet Package Manager -> Package Manager Console)
Open the solution file.
At the right side of the "Package Manager Console," a "Restore" button should appear. Click on the "Restore" button.
Hope that helps you.
I'm not sure if I'm supposed to share the link if I already answered a similar question or just answer again, so I'm doing both. Here's the link to the same answer from a different asker.
Edit:
If after you complete the above steps you are still getting syntax errors from missing references, right-click on References in the Solution Explorer and then just hit OK. That fixed the problem with the references for me.

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 + nuget + TFS: checking in nuget packages?

I'm working on a TFS project with a small team. This project has a bunch of nuget packages installed, but it's for a 4.0 project, and the nuget package manager GUI doesn't even offer the older versions of the packages any longer since their 4.5 equivalents are now being used. In order to allow other team members to compile the project, they need to have the exact versions of the packages. I'd like to check in the entire "packages" folder used by nuget. Is this a good idea? If so, how does one check in the "packages" folder and all its contents since it exists at the solution level? There is no "Include in Solution" option in Visual Studio as there is when you right-click an assembly.
in the past I have also checked in the NuGet packages into version control. With this some problems appeared:
Some packages where not checked into version control when committing from Visual Studio into TFS.
Updating packages became a real problem.
For the first problem I had used the TFS Power Tools. The problem with this solution is that every developer needed to install the Power Tools.
A better solution came up with NuGet 2.7. It introduced package restore. With package restore there's no need to check-in the packages folder. They will be restored during build.
We use an on-prem TFS install with no internet access so we have to check in our package folders or our builds fail. The biggest issue is that VS does not behave consistently when it comes to adding the pending changes for new package files, often times it will ignore the .dll files in the pending changes window, sometimes it adds everything fine.

Error when trying to enable NuGet Package Restore in new Solution

I am getting an error when trying to enable package restore in a new solution I just created. The error in VS2012 is:
NuGet Package Manager
An error occurred while configuring the solution to restore NuGet
packages on build
Unable to read package from path 'NuGet.Build.2.7.0.npkg'.
I tried opening the solution in VS2010 to work around the problem and I am also getting an error when trying to enable package restore, but the message is different:
NuGet Package Manager
An error occurred while configuring the solution to restore NuGet
packages on build
Archive file cannot be size 0.
I tried creating a new solution, but got the same result.
I then tried doing a repair on VS2012 update 3 and rebooting. Still getting the problem.
I also scanned the folder, project, and solution file for anything NuGet or .nupkg, but there is nothing there.
So how can I get this feature working again? The last time I used it was about a week ago, and I don't remember specifically what I changed since then. I uninstalled the VS Power Tools package that I installed about a week ago, but that didn't fix the problem either.
Update
I followed the "removal" instructions here and used a project I already have as a template to enable package restore manually. However, I am still looking for a better solution because this is a feature I use frequently.
I also tried uninstalling and reinstalling NuGet from visual studio, but I still get the same issue. If memory serves correctly, there was a recent NuGet update (is there a log for VS extension installation so I can check?).
I suspect that the NuGet.Build.2.7.0.npkg file is zero bytes due to a failed download. NuGet.Build.2.7.0.npkg is the NuGet package that Visual Studio downloads in order to enable package restore for your solution.
Take a look in your cache and see if this file is zero bytes. If so then delete the file or clearing the cache and try enabling package restore again. The cache is under your profile in a directory similar to:
C:\Users\YourUsername\AppData\Local\NuGet\Cache
You can also browse to the cache from inside Visual Studio by opening the Package Manager Settings, selecting General and clicking the Browse button.
All of the previous answers, plus this one: can you run .\nuget\nuget.exe update -self if this is a solution in which package restore was previously enabled?
check whether your nuget package manager is updated one or not.
Check this from Tools-> Extensions and Updates -> Updates
Update your Nuget Package Manager and then it will work

Resources