Is there a CLI way to list NuGet package updates? - nuget

In Visual Studio, I can right-click the solution, and follow the Manage NuGet Packages for Solution... option to view referenced packages that have updates.
What I'd like to be able to do is to obtain this same information, but from the CLI - either by running a NuGet CLI command or a NuGet PowerShell command. Just a list of packages with updates available, with the current and latest versions would be sufficient.
I've looked through the documentation for both the NuGet CLI and NuGet Powershell, but can't see any candidate commands.
Is this possible? How does the Visual Studio UI pull this information?

I guess Visual Studio is doing this by running two PowerShell commands. First Get-Package, that will list all packages in your project/solution, and then Get-Package -Updates that will list only packages with available updates. After that you can compare two lists, and you will have both current version and latest version. Link to documentation: Get-Package (Package Manager Console in Visual Studio)

I think you could use this command within the package manager console of your solution to get the output you need:
Get-Package -Updates | Select-Object Id, Version, #{Name="CurrentVersion"; Expression ={(Get-Package -filter $_.Id)[0].Versions.Version.ToString()}}
Should get only those packages needing updated and the current version installed.

Related

nuget update -self error

Running nuget update -self from VS 2017 Developer Command Prompt I encountered the following error. How do I make nuget upgrade itself to the latest version?
Checking for updates from https://nuget.org/api/v2/.
Currently running NuGet.exe 2.0.30619.9000.
Updating NuGet.exe to 4.4.1.
The element 'metadata' in namespace 'http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd' has invalid child element 'developmentDependency' in namespace 'http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd'. List of possible elements expected: 'title, tags, summary, licenseUrl, releaseNotes, copyright, description, projectUrl, frameworkAssemblies, language, references, dependencies, iconUrl' in namespace 'http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd'.
How do I make nuget upgrade itself to the latest version?
You can run the command nuget update -self from VS 2017 Developer Command Prompt without following error:
'nuget' is not recognized as an internal or external command, operable
program or batch file.
That means that you should added a path of nuget.exe to the environment variable before or you have a old nuget.exe under the path C:\Users\bboyl\Source.
If you want to update nuget itself, you could manually download the the newer version form nuget.org, Under the section titled "Windows x86 Commandline", replace the old version in the path on your PC.
BTW, It seems the nuget.exe version 2.0.30619.9000 of the system environment variable path is too low to automatically update. So we have to update it manually, just download the new version of nuget.exe.
For example, I have a nuget.exe with version 4.1.0.2450 under the path D:\NuGet4.0, then I set this path into the environment variable. After that, I could update the nuget.exe itself to 4.4.1 in the VS 2017 Developer Command Prompt:
Now we could also update nuget itself with the command nuget update -self.

How to use paket from command line

I installed paket from nuget in Nuget Package Manager Console with:
Install-Package paket
I then tried to run paket convert-from-nuget. It stalled out on a user prompt (it wouldn't let me type into the package manager console). My next thought was to run it from command line, but how to do so is not documented.
Just putting paket convert-from-nuget into a standard dev command prompt results in an error saying "paket" is not recognized.
How do I run paket from the command line or powershell, and how do you specify which solution to work against?
The way to setup paket in your repository is as follow:
1 Download a release of paket.bootstrapper.exe
This is a lightweight utility which obtains and updates paket.exe, pick stable release from official release page:
https://github.com/fsprojects/Paket/releases
2 create a .paket folder
md .paket
3 put the downloaded bootstrapper in this folder and invoke it
cd .paket
paket.bootstrapper
now you have an up-to-date paket.exe ready to ease your handling of dependencies.
4 convert from nuget
cd ..
.paket\paket convert-from-nuget
Please checkout the https://github.com/fsprojects/Paket.VisualStudio also for Visual Studio plugin to help you authoring paket.dependencies and paket.references file
Please also join https://gitter.im/fsprojects/Paket if you have any questions.
The Chocolatey package modifies the PSModulePath envivornment variable. I've observed that sometimes that modification isn't picked up until the system is restarted (or at least not until the user logs out and back in again). In the meantime, you can import the module using:
Import-Module <path-to-packages>\Paket.PowerShell\Paket.PowerShell.psd1
The packages path is usually something like C:\Chocolatey\lib. OTOH, re-reading your question, are you referring to the Nuget inside of Visual Studio? If so, that downloads from NuGet.org and that pkg puts paket.exe in $(SolutionDir)\packages\Pakget.1.18.5\tools\paket.exe. Your version number may varying.
Unfortunately the fact that PowerShell V5 introduces Install-Package (which downloads from Chocolatey by default) is going to get a little confusing vis-a-vie the NuGet Package Manager Console's Install-Package in Visual Studio.

How do you query installed nuget packages with the command line interface?

I need to find the installed version of a package inside my CI build script using the nuget command line.
The "list" command returns ALL packages from the nuget.org feed as far as I can tell. I only want the locally installed packages.
I know how to do this with the VS nuget powershell console. Please do not answer "use get-package". I need to do it with the nuget.exe.
However if there's a way to use the nuget command from plain powershell outside of visual studio that would be acceptable.
nuget list -Source http://my.local.feed/ will list packages available in a local feed, and dir .\packages from within the top-level solution folder will show the packages installed under that location (where .\packages is the install location you have set for the solution).
From http://docs.nuget.org/docs/reference/command-line-reference#List_Command_Options and How do I specify the directory where NuGet packages are installed?

Executing C# code in Nuget Package

I am beginner in creating nuget packages. I created a nuget package which copies all files to solution explorer for now. I am trying to copy folder to users local folder where they have visual studio installed. Can I execute c# code while user installs nuget package on their visual studio solution? Any help would be highly appreciated.
You can add a powershell .ps1 script and set it to be executed while installing the nuget package. If Powershell wouldn't suffice ( most probably it would) and you absolutely want to have some piece of C# code run, just include the code in Powershell as described here: http://blogs.technet.com/b/stefan_gossner/archive/2010/05/07/using-csharp-c-code-in-powershell-scripts.aspx

Nuget Command-line install is not launching Install/Init scripts

I was trying to use Nuget as a software deployment system (repository, versioning and delivery) - idea from Octopus. Previously I was packaging ASP.NET sites into a self-extracting RAR archives with a .CMD startup scripts embeded. Now I'm trying to use Nuget creating puckages during automated build. The issue is that the package installation scripts (tools\Install.ps1 or tools\Init.ps1) do not execute if the package is being installed using command line:
nuget.exe install <package_id> -OutputDirectory <install_folder> -source <local_repo>
Same scripts are able to execute when package installed from Visual Studio Package Manager or Console.
I do not see why this shouldn't be possible given omnipresence of PowerShell.
Am I missing something or this is behaviour by design? Will appreciate you help.
Yes, we did consider MSDeploy but we already have install scripts that do the same thing and give more control and we need some strong package management and repository for build artifacts (something that Java folks do with Maven).
As of today, the powershell scripts are not invoked from doing installations from command line.
One reason for this is that, in general, most of the install/init actions are tied to dte and the visual studio project and doesn't add much value to be able to run it from outside VS.
We have a backlog item for enabling support for exe based scripts too in addition to powershell.