Visual Studio – Client Side Library Manager

I recently was made aware of a new feature of Visual Studio for ASP.NET Core projects the Client Side Library Manager (libman). This new feature is a great time saver for adding all those third-party libraries to your project. This feature is available from Visual Studio 2017 version 15.8 and above.

Adding Libraries to your project

To add a library to your project you can simply right click on the project and go into the Add menu and select add client-side library. In this new pop up window, you can pick the provider to deliver the files and search for the libraries that you want to add to the project.

As you start to type in the Library field results will be populated by IntelliSense and you can select the library you want from the list. The libraries will be the latest available from the provider and their version will be indicated after the @ symbol (as shown below). So if you can’t find the library you are after you can easily try selecting a different provider, cdnjs will be the default provider. In all the examples below I will be using dropzone js as the example library being added to the project.

Once you select a library you can then chose which files you want it to include in your project. The default will be to include all the associated files but if you like you can select only the specific files you need. It will also suggest a target location to install all of these new files, the default option will be in the wwwroot/lib folder but if the wwwroot folder doesn’t exist it will suggest creating the lib folder in the project root.

When you press the install button, Visual Studio will download all the files you have selected into the target location. It will also generate a new file in the project root called libman.json. You can also review the Library Manager feed in the output window.

You can now also check the new libman.json file which will reflect the options you selected in the Library Manager.

Restoring library files

Not only is this a great timesaver but it gets even better, there is an option to restore files on build. In case you’re like me and accidently move or delete files, this option isn’t enabled by default but can be easily switched on by right-clicking on the libman.json file and selecting “Enable Restore Client-Side Libraries on Build”.

If you do not want to switch this on you can also manually restore files at any time by right-clicking on the same file and select “Restore Client-Side Libraries”.

Lessons learnt

When I first tried to install a client library from cdnjs Visual Studio kept saying there was issues downloading the files and simply just refused to restore the files. I couldn’t find any other posts about this issue and eventually a simple reboot of my laptop sorted the issue (typical eh?).

Personally I hate searching for libraries to add to my projects and all the faff with downloading the files and adding them to source countrol etc.. Where as this new manager does everything for you without leaving the safety of Visual Studio. Its a great timesaver and one of my new favourite features.

Leave a Reply

Your email address will not be published.