Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore bower components on Visual Studio build

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?

like image 364
Andrzej Gis Avatar asked Aug 29 '15 23:08

Andrzej Gis


People also ask

How to install Bower components in Visual Studio?

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.

How do I install Bower components?

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.

What is Bower Visual Studio?

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.

Is Bower deprecated?

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.


1 Answers

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: enter image description here

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.

like image 174
Andrzej Gis Avatar answered Nov 10 '22 23:11

Andrzej Gis