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.
Related
This is a project that's being cloned from Git, my references are all showing that it could not be found, even though some of it is built in system reference. This solution was cloned from a Git Repository, and I have "Allow NuGet to download missing packages" and "Automatically check for missing packages during build in Visual Studio" checked. Furthermore, the path is Nuget.Config to all the packages is valid.
When I try to do "Restore Nuget Packages" on the solution, it says "All packages are already installed and there is nothing to restore. There is no framework version issues either.
I have tried the following:
Uninstalled Visual studio and reinstalling it.
Clean solution, restore package and Rebuild the project
Reinstalled all the Nuget packages by using update-package PackageName "" -reinstall
Screenshot of Error List
1) First, you should make sure that your VS has installed the related Net Framework SDK. If the git project targets to Net Framework 4.8, you should install the Net Framework 4.8 Developr SDK on your current PC.
2) Second, when you finish it, close VS, delete .vs hidden folder under the solution folder, bin and obj folder of the project.
3) Third, restart your project under then run update-package -reinstall under Tools-->Nuget Package Manager-->Package Manager Console
Update 1
The issue is that the the hintpath of the nuget package from csproj file is not right. After changing the hintpath to the right ones under the PC, all works well.
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
I have downloaded all the packages using "Restore NuGet packages" that existed in packages.config
However, they do not appear in the References, so VS is not aware of them.
Is there a way to add them automatically to the reference list? Possibly in 1 step?
The references are tracked as part of the project files and are usually added as part of a NuGet package's initial installation. Restoring the packages will just download them.
This means it sounds like you need to reinstall those specific packages whose references are missing.
To do this, run the Update-Package command in the Package Manager Console with the -reinstall flag on it.
Update-Package <package_name> -ProjectName MyProject -reinstall
Optionally, you can add the -Version flag if you need to stick with a version that's not the latest, just make this version number match that stored in your packages.config file.
Or alternatively, to reinstall all packages for a given project:
Update-Package -Reinstall -ProjectName <project_name>
I too have VS 2017. However, I haven't encountered any problem with Nuget packages.
Anyway, try this: Right-click the References folder in the project, then click "Manage Nuget Packages" then click "Restore".
If that doesn't work, close VS, delete all files in bin, obj and packages folders and then repeat the steps above.
Also make sure the items "Allow NuGet to download missing packages" and "Automatically check for missing packages during build..." are checkekd in Tools/Options/Nuget Package Manager setting as follows:
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.
For some reason Nuget ignores the default project I select from the drop down and always installs packages into my startup web project. I have a utility project, specifically for things like library dependencies and want Nuget to install packages there, but it always goes for the web project.
EDIT:
I eventually figured this out. It turns out that the solution file was under one particular projects directory. This was not how I normally create a solution, but I didn't create this originally so it didn't occur to me that this was the cause.
Try using command with project name
PM> Install-Package EntityFramework -ProjectName DataProvider
or Just right click on the Solution and select Manage NuGet Packages.
when you install it allows selecting the set of projects to install the package into.