How to use Bootstrap 4 in ASP.NET Core

前端 未结 10 929
故里飘歌
故里飘歌 2020-12-04 05:11

I want to update Bootstrap in ASP.NET Core with NuGet. I used this:

Install-Package bootstrap -Version 4.0.0

It did add the dependencies bu

相关标签:
10条回答
  • 2020-12-04 05:31

    BS4 is now available on .NET Core 2.2. On the SDK 2.2.105 x64 installer for sure. I'm running Visual Studio 2017 with it. So far so good for new web application projects.

    0 讨论(0)
  • 2020-12-04 05:34

    What does the trick for me is:

    1) Right click on wwwroot > Add > Client Side Library

    2) Typed "bootstrap" on the search box

    3) Select "Choose specific files"

    4) Scroll down and select a folder. In my case I chose "twitter-bootstrap"

    5) Check "css" and "js"

    6) Click "Install".

    A few seconds later I have all of them wwwroot folder. Do the same for all client side packages that you want to add.

    0 讨论(0)
  • 2020-12-04 05:42

    Libman seems to be the tool preferred by Microsoft now. It is integrated in Visual Studio 2017(15.8).

    This article describes how to use it and even how to set up a restore performed by the build process.

    Bootstrap's documentation tells you what files you need in your project.

    The following example should work as a configuration for libman.json.

    {
      "version": "1.0",
      "defaultProvider": "cdnjs",
      "libraries": [
      {
        "library": "twitter-bootstrap@4.2.1",
        "destination": "wwwroot/lib/bootstrap",
        "files": [
        "js/bootstrap.bundle.js",
        "css/bootstrap.min.css"
        ]
      },
      {
        "library": "jquery@3.3.1",
        "destination": "wwwroot/lib/jquery",
        "files": [
          "jquery.min.js"
        ]
      }
    ]
    }
    
    0 讨论(0)
  • 2020-12-04 05:45

    Looking into this, it seems like the LibMan approach works best for my needs with adding Bootstrap. I like it because it is now built into Visual Studio 2017(15.8 or later) and has its own dialog boxes.

    Update 6/11/2020: bootstrap 4.1.3 is now added by default with VS-2019.5 (Thanks to Harald S. Hanssen for noticing.)

    The default method VS adds to projects uses Bower but it looks like it is on the way out. In the header of Microsofts bower page they write:

    Following a couple links lead to Use LibMan with ASP.NET Core in Visual Studio where it shows how libs can be added using a built-in Dialog:

    In Solution Explorer, right-click the project folder in which the files should be added. Choose Add > Client-Side Library. The Add Client-Side Library dialog appears: [source: Scott Addie 2018]

    Then for bootstrap just (1) select the unpkg, (2) type in "bootstrap@.." (3) Install. After this, you would just want to verify all the includes in the _Layout.cshtml or other places are correct. They should be something like href="~/lib/bootstrap/dist/js/bootstrap...")

    0 讨论(0)
  • 2020-12-04 05:47

    Use nmp configuration file (add it to your web project) then add the needed packages in the same way we did using bower.json and save. Visual studio will download and install it. You'll find the package the under the nmp node of your project.

    0 讨论(0)
  • 2020-12-04 05:49

    Unfortunately, you're going to have a hard time using NuGet to install Bootstrap (or most other JavaScript/CSS frameworks) on a .NET Core project. If you look at the NuGet install it tells you it is incompatible:

    if you must know where local packages dependencies are, they are now in your local profile directory. i.e. %userprofile%\.nuget\packages\bootstrap\4.0.0\content\Scripts.

    However, I suggest switching to npm, or bower - like in Saineshwar's answer.

    0 讨论(0)
提交回复
热议问题