I've just created my first ASP.NET 5 MVC 6 project in VS 2015. The web application project that comes out of the box.
I figured out that bower components are stored in wwwroot/lib
folder. I made an experiment and deleted it. After that I rebuilt the project and the bower components were not restored.
Calling bower install
manually in console restored the files.
How do I make Visual Studio restore bower files automatically on build?
To add new package, you can get the Visual Studio GUI for Bower by right clicking project in solution explorer and selecting “Manage Bower Packages..” This will bring a GUI similar to the Nuget GUI. You can search and install the package you required similar to below image.
Installing Bower Bower can be installed using npm, the Node package manager. If you don't already have npm installed, head over to the Node. js website and download the relevant copy of Node. js for your system.
Bower is a popular package management system for managing static content used by client-side web applications. Visual Studio provides rich support for Bower, including templates and package management tools.
Bower has been deprecated by its creators After a long and heated debate on Github, the creators of Bower decided it does not add value to the current web development stack and should be discontinued.
I figured out a way to do this, though I don't really like it. I'll be happy to accept a better answer.
In project's gulpfile.js the first line is a comment"
/// <binding Clean='clean'/>
It hooks to Visual Studio Clean
event and binds clean
Gulp task to it.
You can hook to other events e.g. After Build
. I bound it with a task that uses gulp-bower to restore the components.
gulpfile.js
/// <binding Clean='clean' AfterBuild='after_build'/>
var gulp = require("gulp"),
bower = require('gulp-bower');
...
gulp.task("after_build", function() {
return bower()
.pipe(gulp.dest(paths.webroot + 'lib/'));
});
You can see the bindings in Task Runner Explorer
:
This solution seems kind of clumsy though. I'd rather have the kpm-utility do the job.
EDIT
Actually there is no need for restoring the packages on build. They are restored when you open the project in VS. However I don't know what happens when you update your sources from code repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With