Skip to content
  • iImagine
  • Register
  • Log In

Web Development School

Learning made easy.

  • Books
    • Beginning Web Development with ASP.Net Core & Client-Side Technologies
      • TOC
      • Part 1
        • Chapter 1: Static HTML – Designing the landing page
      • Part 2
        • Chapter 2: ASP.Net Core – Let’s talk Dynamic
        • Chapter 3: Introduction to ASP.Net Core MVC
          [ASP.Net Core v9]
      • Part 4
        • Chapter 7: Using Server Side & Client Side technologies together
          [ASP.Net Core v7 & Angular 15]
  • Environment Setup
    • Installing Angular
    • Installing Visual Studio 2022
    • Installing SQL Server 2022 Express
    • Installing Postman
    • Installing Git for Windows
  • Blog
  • iImagine WebSolutions
  • Events
  • Learning Videos
  • Toggle search form

Install Bootstrap using Libman

We used the Bootstrap client-side package back in Chapter 1 to improve the look of our application, make CSS easier to work with, and to take advantage of its grid system. There we just copied the link to the bootstrap.min.css file from the Bootstrap site and pasted it in.

In ASP.Net Core MVC, client-side packages are installed using a DotNet tool called Libman. So, we need to install Libman first in order to use it to install Bootstrap.

Table Of Contents
  1. Install Libman
  2. Install Bootstrap
    • Create the libman.json file
    • Install the Bootstrap package
  3. Enable Static file serving
  4. What's Next

Install Libman

Open a Console window and set the path to the FredsCars directory containing the FredsCars.csproj file and type the following command to clear out any existing prior version of a Libman install.

dotnet tool uninstall --global Microsoft.Web.LibraryManager.Cli

Next, making sure your console prompt is still pointing to the FredsCars project folder, enter the following command.

dotnet tool install --global Microsoft.Web.LibraryManager.Cli --version 2.1.175

Now check the version of Libman to make sure it is installed by entering the following command into the console.

Libman --verion

Install Bootstrap

Create the libman.json file

Now that we have Libman installed, we can use it to install Bootstrap. Enter the following command into the Console window and press enter.

libman init -p cdnjs

As a result of the command a libman.json file gets created on the root of the FredsCars project.

Double click the libman.js file to open it in a Visual Studio tab and look at the generated JSON configuration code.

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": []
}

The default provider is cndjs because we included the -p cdnjs switch in the command.

cdnjs is a Content Delivery Network (CDN) for client-side packages. This is the same CDN the Bootstrap link uses back in Chapter 1. Other options for CDNs are jsDelivr and unpkg.

Install the Bootstrap package

Run the following command in the FredsCars project folder.

libman install bootstrap -d wwwroot/lib/bootstrap

The above command is saying to install the latest Bootstrap distribution into a lib/bootstrap folder under the newly created wwwroot folder. Once the command is complete, your project structure should look like the screenshot below.

Notice the globe icon to the left of the wwwroot folder in the Solution Explorer. This signifies that wwwroot is a special folder in ASP.Net Core MVC. This is where we place all of our static files such as CSS files (which BootStrap is), JavaScript files, images, and any other static files like pdf(s).

And now libman.js has been updated with the Bootstrap client-side package library with the latest version (at the time of this writing), 5.3.3.

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": [
    {
      "library": "bootstrap@5.3.3",
      "destination": "wwwroot/lib/bootstrap"
    }
  ]
}

You could also type the new code above directly in libman.js and the Bootstrap package would show up under wwwroot/lib/bootstrap indicated by the destination property.

Enable Static file serving

In order for static files to be served from our wwwroot folder, we need to include the UseStaticFiles middleware component in Program.cs. Let’s add that in now before we move on.

var builder = WebApplication.CreateBuilder(args);

// Add Services
builder.Services.AddControllersWithViews();

var app = builder.Build();

// Configure the HTTP request pipeline.

app.UseStaticFiles();

/*** Add endpoints for contoller actions and
       the default route ***/
app.MapDefaultControllerRoute();

app.Run();

NOTE: Supposedly, UseStaticFiles() is added in automatically in .Net 6 and later. And I had the application working without it at one point. But, I started getting cross-origin errors for the Bootstrap.min.cs file. Adding it back in explicitly seemed to get rid of the error.

What’s Next

In this module we installed the DotNet Libman tool and used it to install Bootstrap. Now that we have the Bootstrap package installed and ready to go, we can create the Layout template and create a common look and feel for our website. And, the Bootstrap CSS file will be available for us to apply Bootstrap styling.

< Prev
Next >

Leave a ReplyCancel reply

Chapter 1: Static HTML – Designing the landing page.

  • Static HTML – Designing the landing page.
  • Let’s get started!
  • Mock your site with HTML
  • Make CSS easy with Bootstrap
  • Mock your content
  • Introducing JavaScript
  • JavaScript Code Improvements
  • Results Data
  • Images and the HTML Image Element.
  • Revisiting Reusability for CSS and JavaScript
  • Reuse for HTML: PART 1
  • Reuse for HTML: PART 2
  • Details Page – Using a Bootstrap Component
  • Creating Links
  • Chapter One Conclusion

Chapter 2: ASP.Net Core – Let’s talk Dynamic

  • Introduction to ASP.Net Core
  • What is .Net?
  • What is ASP.Net
  • Introduction to Entity Framework Core

Chapter 3: ASP.Net MVC Core – Models, Views, and Controllers [ASP.Net Core v9]

  • Introduction to ASP.Net Core MVC
  • Create the project: ASP.Net Core MVC
  • Explore the ASP.Net Core Empty Web Project Template
  • Configure the Application for MVC
  • Create a Controller: Home Controller
  • Create a View: Index View for the Home Controller
  • Install Bootstrap using Libman
  • Create the Layout template
  • Create the Model
  • Install EF Core & Create the Database
  • Seed the Database: Loading test data
  • DI (Dependency Injection): Display a List of Vehicles
  • Repository Pattern: The Vehicles Repo
  • Unit Test 1: Home Controller Can Use Vehicle Repository
  • Unit Test 2: Vehicle Repository Can Return List
  • Add the ImagePath Migration and Thumbnail images to results
  • Pagination: Create a Custom Tag Helper
  • Sorting
  • Category Filter
  • Partial View: Break out the vehicle results
  • View Component: Create dynamic category buttons
  • Create the Details page
  • Create the Create Page

Chapter 7: Using Server Side & Client Side technologies together. [ASP.Net Core v7 & Angular v15]

  • Intro to Full Stack Development
  • Fred’s Cars – Full Stack Development
  • Prepare the environment
  • Create the Visual Studio Solution
  • Add the ASP.Net Core Web API project
  • Add the Angular Project
  • Wire it up!
  • WeatherForecast: Understanding the basics
  • Vehicles API Controller: Mock Data
  • Vehicles Angular Component: Consuming Data
  • Routing and Navigation
  • Using a Component Library: Angular Material
  • Our first Angular Material Component: MatToolbar
  • Configuring for Saas: CSS with superpowers
  • Create the Header & Footer components
  • Displaying Results with MatTable
  • Loading: Using a Progress Spinner
  • MatTable: Client-Side Paging and Sorting
  • MatSidenav: Create a Search Sidebar
  • MatCheckbox: Category Search UI
  • Adding an image to the welcome page
  • Create the database with Entity Framework Core migrations
  • MatPaginator & PageEvent: Custom Server-Side Paging
  • Unit Testing: Custom Server-Side Paging
  • Repository Pattern: VehicleRepository
  • Unit Test: Paging in the Vehicles controller
  • Server-Side Sorting
  • Unit Tests: Sorting
  • Filter (Quick Search)
  • Unit Tests: Filter feature
  • Advanced Search: Categories
  • Unit Tests: Search by category
  • Progress Spinner: Final Fix

TOC

  • What were WebForms?
  • Enter MVC
    • Understanding MVC
    • Advantages of MVC
  • ASP.Net Core MVC – A total rewrite
  • ASP.Net Core 2 MVC – Here come Razor Pages
    • Understanding Razor Pages
  • ASP.Net Core 3 – Dropping the MVC reference
    • Understanding Blazor
  • Dropping the MVC reference
  • Hello .Net 5!
  • What’s Next? – Here comes .Net 6.

Recent Posts

  • Angular Commands Cheat Sheet
  • Installing Git for Windows
  • Installing Postman
  • Installing SQL Server 2022 Express
  • Installing Visual Studio 2022

Recent Comments

No comments to show.

Archives

  • November 2023
  • October 2023
  • June 2023
  • October 2021

Categories

  • Angular
  • ASP.Net
  • Environment Setup
  • See All
  • SQL Server
  • Visual Studio
  • Web API & Rest Services

WordPress Theme Editor

Copyright © 2025 Web Development School.

Powered by PressBook Blog WordPress theme