8

I have installed Install-Package bootstrap.sass in ASP .net core 3.1.

It has installed bootstrap.js and scss folder. But how to compile the bootrap.scss and use that in the _Layout?

I tried to import the bootstrap from scss but it gives me the error as: enter image description here

The NuGet has installed the following file:

enter image description here

1 Answer 1

28

You can follow the steps below to set up Bootstrap 5 SASS using ASPNET Core.

  1. Delete the /wwwroot/lib/bootstrap folder:
    • If your application already contains Bootstrap, you will need to delete these files.
  2. Choose the scss folder and click install:
    • You can right-click wwwroot and select Add->Client-Side Library. Select unpkg provider, "[email protected]" library.
    • [enter image description here1
  3. You can create a file called bootstrap.custom.scss for testing.
    • You can right-click the bootstrap.custom.scss file and select Web Compiler->Compile file.
      • If you cannot find the Web Compiler option, you need to click this link to install the Web Compiler tool, and then restart VS.
    • bootstrap.custom.scss
      • $primary: #00ffff;
        $white:white;
        @import "../lib/bootstrap/scss/bootstrap";
        nav.navbar {
            background: linear-gradient($primary, $white)
        }
        
    • Modify the _Layout view
      • ... ...
        @*<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />*@
        <link href="~/css/bootstrap.custom.css" rel="stylesheet" />
        ... ...
        @*<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>*@
        ... ...
        
    • Result
      • enter image description here
2
  • 1
    Thank you for the other workaround. but my question is specifically related to the nugget package manager.
    – Rasik
    Commented Jun 3, 2021 at 14:40
  • There are two ways to add Library files in ASP.NET Core projects(link)the Add Client-Side Library dialog or Manually configure LibMan manifest file entries.
    – Yihui Sun
    Commented Jun 4, 2021 at 9:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.