Libman

Library Manager (LibMan) is a lightweight, client-side library acquisition tool. LibMan downloads popular libraries and frameworks from the file system or from a content delivery network (CDN)

For the life of me I cannot figure out why a libman.json file is not included by default when I scaffold an ASP.NET MVC project - this file is used by Library Manager (LibMan) to download the libraries that the scaffold brought down for me in wwwroot\lib. These are things like bootstrap and jquery.

As soon as I add this folder to my .gitignore (example below) they wont be commited which means when another developer pulls down the repository or I delete the folder and clone again the client side files are not there and the UI looks like trash :(

So what I now do is create the libman.json file as soon as possible.

1
2
3
4
5
6
7
8
lib
packages
*.suo
*.vs
.vs
/.vs/config/applicationhost.config
bin
obj

Thankfully Visual Studio has this Manage Client-Side Libraries... option which lets me search for these files and add them.

Manage client side libraries

Selecting this option will open the json file which can be manually edited.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"version": "1.0",
"defaultProvider": "unpkg",
"libraries": [
{
"library": "bootstrap@5.1.0",
"destination": "wwwroot/lib/bootstrap/"
},
{
"library": "jquery@3.5.1",
"destination": "wwwroot/lib/jquery/"
},
{
"library": "jquery-validation@1.19.3",
"destination": "wwwroot/lib/jquery-validation/"
},
{
"library": "jquery-validation-unobtrusive@3.2.11",
"destination": "wwwroot/lib/jquery-validation-unobtrusive/"
}
]
}

Alternatively in solution explorer, right-click the folder wwwroot and choose Add > Client-Side Library

Add client side library

I’ve had luck with providers cdnjs and unpkg.

If you then delete wwwroot/lib or clone a project that had this excluded you can restore the libraries by right clicking libman.json and selecting Restore Client-Side Libraries

Restore Client-Side Libraries

References