Zombie Bower Packages in Visual Studio 2015

Are you playing with Visual Studio 2015 and ASP.NET 5.0 (vNext) yet? Good! If you are you may have noticed this little quirk when using Bower packages.

If you open up bower.json and add a package (for example angular) and then build then as part of the build process the missing Angular.js package will be downloaded (expected). Now let's say that you've changed your mind and you don't want to use Angular.js. You could go back into the bower.json file and remove the dependency there. You would also need to go to the wwwroot/libs folder and remove the angular directory that is present there.

Now here is the thing, if you save the file and do another build the angular directory in wwwroot/libs will be recreated even though Angular.js is no longer a dependency in the bower.json file. Turns out to stop it getting restored you need to also remove the angular directory off the root of the web project in the bower_components directory.

As you can see in the screenshot above, you need tom remove the three highlighted things above to stop those packages reappearing. This isn't actually a problem with Visual Studio 2015. I can replicate the same thing using grunt, bower and grunt-bower-task on a hand-crafted Node.js app on my MacBook.

I suspect that the grunt-bower-task install task doesn't really refer to the bower.json file prior to just enumerating over the contents of the bower_components directory (could be wrong about this as I've only skimmed the source code on GitHub).

Anyway, thought I would point it out because the behaviour can be frustraiting when you don't know what is going on.