PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, November 21, 2022

[FIXED] How to force Nuget Restore using Powershell?

 November 21, 2022     nuget, nuget-package-restore, package, powershell, visual-studio     No comments   

Issue

I'd like to force NuGet to restore my NuGet packages. Going to my solutions directory and type NuGet restore, even with the latest downloaded NuGet.exe doesn't work.

As explained here, I can do this in a Powershell prompt, using the Update-Package command (as I prefer not to use my Visual Studio environment).

However, my Powershell seems not to understand Update-Package, although I have a +5 version:

PowerShell Prompt> Get-Host | Select-Object Version

Version
-------
5.1.19041.1023


PowerShell Prompt> Update-Package -reinstall
Update-Package : The term 'Update-Package' is not recognized as the name of a cmdlet, function,
script file, or operable program.
Check the spelling of the name, or if a path was included, verify that 
the path is correct and try again.
At line:1 char:1
+ Update-Package -reinstall
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Update-Package:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

What can I do in order to launch Update-Package successfully in my Powershell?

Thanks in advance


Solution

Standard powershell doesn't ship have NuGet restore functionality.

If you refer to https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio, and https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore, you will see that there are 5 ways to use NuGet.

  • Visual Studio (and MSBuild.exe)
  • Visual Studio for Mac
  • dotnet CLI
  • NuGet.exe CLI
  • Package Manager Console (in Visual Studio)

There is no functionality built into powershell.

Your only options are to build on top of the above mentioned tooling.

  • Call dotnet.exe restore
  • Call nuget.exe restore
  • Call msbuild.exe restore.


Answered By - imps
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing