Web package manager Bower is well-integrated in Visual Studio project templates like ASP.NET Core, but not for .NET Core console applications at the moment.
However, it would be useful if you are using e.g. a self-hosted webserver in your application, like Nancy, and you do not want to rely on CDN providers when using Bootstrap or similar tools.
This short tutorial describes how to get Bower running in Windows, Visual Studio 2017, in a .NET Core console application.
Steps to install Bower
Visual Studio Extensions
Those are optional, but useful. I recommend to install the following packages. Simply search and install them via VS -> Extras -> Extensions and Updates.
- Open Command Line (Mads Kristensen)
- to get a CMD shell shortcut within your VS project (right-click project name in Solution Explorer)
- Package Installer (Mads Kristensen)
- Simple GUI to avoid typing commands for package installations
Run Manage NuGet packages (e.g. via right-click on project in Solution Explorer).
Install package Bower.
If you haven’t installed Git yet, you would later encounter error messages that Bower cannot find ENOGIT:
bower ENOGIT git is not installed or not in the PATH
Get Git from here and install it.
Important: Re-open Visual Studio and any command-line windows to get the updated PATH variable.
Test it by installing a package like bootstrap-table.
Use either the package installer („Quick install package“)…
…or use the command-line:
bower install bootstrap-table
Afterwards, you should find a new subfolder „bower_components“ and the bower.json config file in your project.
It might be a good idea to exclude bower_components from your version control system.
Unfortunately, the bower management GUI like in ASP.NET Core seems not to be available for Core console apps yet.
It might happen that bower command does not get recognized (error „no executable found“).
To solve this, fix the system PATH variable, e.g. with a PowerShell command:
[Environment]::SetEnvironmentVariable("Path", $env:path + ";C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Web\External", [EnvironmentVariableTarget]::Machine)