- Visual Studio 2017 Package Manager Console
- Visual Studio Package Manager Console Shortcut
- Visual Studio Package Manager Console Disabled
One approach is to use the sources command: nuget.exe sources Add Update -Name feedName -UserName user -Password secret. With this you can either add that source with the credentials or update an existing one. It works perfectly. The Package Manager Console is a PowerShell console within Visual Studio used to interact with NuGet and automate Visual Studio. You can access the Package Manager Console from within Visual Studio by going to Tools - Library Package Manager - Package Manager Console. The following is a screen shot for the console. The console is built into Visual Studio on Windows. Open your project or solution in Visual Studio, and then open the Package Manager Console in Visual Studio by navigating to Tools NuGet Package Manager Package Manager Console. By default, console commands operate against a specific package source and project as set in the control at the.
-->The NuGet Package Manager Console lets you use NuGet PowerShell commands to find, install, uninstall, and update NuGet packages. Using the console is necessary in cases where the Package Manager UI does not provide a way to perform an operation. To use nuget.exe
CLI commands in the console, see Using the nuget.exe CLI in the console.
The console is built into Visual Studio on Windows. It is not included with Visual Studio for Mac or Visual Studio Code.
Important
The commands listed here are specific to the Package Manager Console in Visual Studio, and differ from the Package Management module commands that are available in a general PowerShell environment. Specifically, each environment has commands that are not available in the other, and commands with the same name may also differ in their specific arguments. When using the Package Management Console in Visual Studio, the commands and arguments documented in this present topic apply.
Find and install a package
For example, finding and installing a package is done with three easy steps:
Open the project/solution in Visual Studio, and open the console using the Tools > NuGet Package Manager > Package Manager Console command.
Find the package you want to install. If you already know this, skip to step 3.
Run the install command:
Important
All operations that are available in the console can also be done with the NuGet CLI. However, console commands operate within the context of Visual Studio and a saved project/solution and often accomplish more than their equivalent CLI commands. For example, installing a package through the console adds a reference to the project whereas the CLI command does not. For this reason, developers working in Visual Studio typically prefer using the console to the CLI.
Tip
Many console operations depend on having a solution opened in Visual Studio with a known path name. If you have an unsaved solution, or no solution, you can see the error, 'Solution is not opened or not saved. Please ensure you have an open and saved solution.' This indicates that the console cannot determine the solution folder. Saving an unsaved solution, or creating and saving a solution if you don't have one open, should correct the error.
Opening the console and console controls
Open the console in Visual Studio using the Tools > NuGet Package Manager > Package Manager Console command. The console is a Visual Studio window that can be arranged and positioned however you like (see Customize window layouts in Visual Studio).
By default, console commands operate against a specific package source and project as set in the control at the top of the window:
Selecting a different package source and/or project changes those defaults for subsequent commands. To overrride these settings without changing the defaults, most commands support
-Source
and-ProjectName
options.To manage package sources, select the gear icon. This is a shortcut to the Tools > Options > NuGet Package Manager > Package Sources dialog box as described on the Package Manager UI page. Also, the control to the right of the project selector clears the console's contents:
The rightmost button interrupts a long-running command. For example, running
Get-Package -ListAvailable -PageSize 500
lists the top 500 packages on the default source (such as nuget.org), which could take several minutes to run.
Install a package
See Install-Package.
Installing a package in the console performs the same steps as described on What happens when a package is installed, with the following additions:
- The Console displays applicable license terms in its window with implied agreement. If you do not agree to the terms, you should uninstall the package immediately.
- Also a reference to the package is added to the project file and appears in Solution Explorer under the References node, you need to save the project to see the changes in the project file directly.
Uninstall a package
See Uninstall-Package. Use Get-Package to see all packages currently installed in the default project if you need to find an identifier.
Uninstalling a package performs the following actions:
- Removes references to the package from the project (and whatever management format is in use). References no longer appear in Solution Explorer. (You might need to rebuild the project to see it removed from the Bin folder.)
- Reverses any changes made to
app.config
orweb.config
when the package was installed. - Removes previously-installed dependencies if no remaining packages use those dependencies.
Update a package
See Get-Package and Update-Package
Find a package
See Find-Package. In Visual Studio 2013 and earlier, use Get-Package instead.
Availability of the console
Starting in Visual Studio 2017, NuGet and the NuGet Package Manager are automatically installed when you select any .NET-related workloads; you can also install it individually by checking the Individual components > Code tools > NuGet package manager option in the Visual Studio installer.
Also, if you're missing the NuGet Package Manager in Visual Studio 2015 and earlier, check Tools > Extensions and Updates... and search for the NuGet Package Manager extension. If you're unable to use the extensions installer in Visual Studio, you can download the extension directly from https://dist.nuget.org/index.html.
The Package Manager Console is not presently available with Visual Studio for Mac. The equivalent commands, however, are available through the NuGet CLI. Visual Studio for Mac does have a UI for managing NuGet packages. See Including a NuGet package in your project.
The Package Manager Console is not included with Visual Studio Code.
Extend the Package Manager Console
Some packages install new commands for the console. For example, MvcScaffolding
creates commands like Scaffold
shown below, which generates ASP.NET MVC controllers and views:
Set up a NuGet PowerShell profile
A PowerShell profile lets you make commonly-used commands available wherever you use PowerShell. NuGet supports a NuGet-specific profile typically found at the following location:
%UserProfile%DocumentsWindowsPowerShellNuGet_profile.ps1
To find the profile, type $profile
in the console:
For more details, refer to Windows PowerShell Profiles.
Use the nuget.exe CLI in the console
To make the nuget.exe
CLI available in the Package Manager Console, install the NuGet.CommandLine package from the console:
Visual Studio 2017 Package Manager Console
What is the problem ?
.NET developers usually use NuGet as a Packet Manager.
Despite being able to deal with JavaScript packages, NuGet is not the best option for them.
So, a long time ago, Microsoft implemented native Bower support in Visual Studio, but Bower was deprecated in 2018:
So, some time ago, Microsoft created the LibPack to replace Bower in Visual Studio:
But there is a much better solution than Bower ou LibMan: npm.
npm is the Package Manager for Node.js and you, probably, will find there any JavaScript library you want.
Visual Studio has native support to npm, but I do not like the way it works.
So I changed it a little…
How does npm work ?
npm manages and downloads JavaScript packages, very close to the way NuGet does with .NET Packages.
Below you find a naive comparison of both:
npm | NuGet | |
---|---|---|
Site | npm | NuGet |
File | package.json package-lock.json | packages.json |
Packages | JavaScript | .NET JavaScript |
The first npm goal is supporting Node.js: the well known JavaScript Server.
npm is a command-line tool and ( like Git ) you will feel better using it this way.
How does Visual Studio deal with NuGet ?
The NuGet packages are managed by Nuget Package manager both visually and by Package Manager Console.
NuGet keeps a CACHE with all downloaded packages ( since ever ! ) in the following directory:
You may change the location of this CACHE with the following command:
Below you find the project structure created for an ASP.NET Mvc Project with NuGet:
As you can see, the packages are download BY SOLUTION and NuGet automatically manages multiple versions.
Below you find the project structure created for an ASP.NET Core Mvc Project with NuGet:
As you can see, there are no packages directory and package.json file.
This is because all packages are kept in CACHE directory ( see above ) and Projects reference them in a different way.
HINT
I EXCLUDE packages directory ( and node_modules ) from Git versioning by including it in .gitgnore file:
Is does not make sense versioning something that is downloaded from Web any time you want.
You just download all packages after cloning the repository.
Visual Studio Package Manager Console Shortcut
NuGet is a well-established technology and really useful for developers.
How does Visual Studio deal with npm ?
DON’T DO THIS: I WILL CHANGE IT IN THE NEXT TOPIC BELOW !
To get npm you need to download and install Node.js:
HINT
Do not install NPM Tools for Native Modules.
npm keeps a CACHE with all downloaded packages ( since ever ! ) in the following directory:
You may change the location of this CACHE with the following command:
To begin with npm you create the package.json file in your ASNET MVC or ASP.NET Core MVC Project:
The file will be created empty but below you find the complete file:
The devDepencies are packages you require for Development ( see Gulp below ).
The dependencies are packages you require for run-time.
To get the same result with command line you may open the Command Line in the PROJECT directory and run the following commands:
The init command will create the package.json file.
The install command will download the package and update the package.json file ( –save ).
The update command will download the packages listed in package.json file.
Visual Studio Package Manager Console Disabled
Eventually you will find a package-lock.json file.
It contains detailed information about the dependencies between packages.
Should you delete it, you may recreate it with the following command:
There is a nice extension for Visual Studio to open the Command Line without going to Windows Explorer and typing “cmd”:
To force an update you clean the SOLUTION:
Below you find the project structure created for an ASP.NET Mvc Project with npm:
But, you end up with 291 packages, 3.593 files and 8.97 MB ( Visual Studio 16.4 + ASP.NET Core MVC 3.1 ), not just the 4 packages you asked for !
The final result will be the following:
- A node_modules PER PROJECT, instead of PER SOLUTION like you get with NuGet.
- If you have more than one MVC Project per Solution, you will have multiple node_modules directories.
- Package Manager Console will not work, complaining a missing package.json for the SOLUTION.
- 291 packages, 3.593 files and 8.97 MB in the node_modules.
Well, there are some things we may improve here…
How do I deal with npm ?
Below you find the project structure I create for an ASP.NET Core Mvc PROJECT with npm:
First, take care of your PROJECT !
Create an empty package.json ( DO NOT INCLUDE ANY PACKAGE ! ) file in your PROJECT:
This file will be visible inside Visual Studio in your PROJECT !
Go to command line at your PROJECT directory and execute the following commands.
The commands below install del and gulp in the global npm directory ( see npm CACHE directory above ):
The commands below may be used to update these packages, when necessary:
The commands below create a symbolic link from global npm directory into the node_modules of your PROJECT:
With the symbolic link, you have just 1 copy of these packages in the global npm directory !
If you don´t install these packages in your PROJECT, Visual Studio will complain about Gulp and the Task Runner Explorer ( see Gulp below ) will not work.
Second, take care of your SOLUTION.
Create a package.json file in your SOLUTION directory:
If you add this file to your solution it will be visible in a ( Solution ) folder named “Solution Items”.
Go to command line at your SOLUTION directory and execute the following command:
You may also use the Visual Studio Package Manager Console:
Visual Studio -> Tools – NuGet Package Manager -> Package Manager Console
The final result will be the following:
- A node_modules PER SOLUTION, like NuGet.
- If you have more than one MVC Project per Solution, you will have only 1 node_modules directory.
- Package Manager Console will work perfectly with npm, for install/update/uninstall.
- Task Runner Explorer ( see Gulp below ) will work perfectly.
How does Visual Studio deal with Gulp ?
Gulp is a wonderful Task Automation JavaScript Tool fully integrated in Visual Studio.
As the JavaScript packages are downloaded in node_modules directory, Gulp will help us to copy the files we really need to:
- /Context and /Scripts directories for ASP.NET MVC Application
- /wwwroot directory for ASP.NET MVC Core Application
The example below is for ASP.NET Core, but may be easily adapted to ASP.NET MVC.
To begin just add a gulpfile.js to your PROJECT with the following content:
I guess the code is quite easy to understand.
As you can see it needs del and gulp packages to run.
This file will create two tasks: npm-copy and npm-delete.
To execute it just right-click the file above and select Task Runner Explorer.
After running the npm-copy Task I get the following structure under my wwwroot directory:
Epilogue
Please, let me know if it works for you or you have any comments.