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 but how do I add it to my project now? What is the path for local NuGet dependencies?
This question is related to
.net
asp.net-core
nuget
bootstrap-4
asp.net-core-2.0
Why not just use a CDN? Unless you need to edit the code of BS, then you just need to reference the codes in CDN.
See BS 4 CDN Here:
https://www.w3schools.com/bootstrap4/bootstrap_get_started.asp
At the bottom of the page.
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.
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...")
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": "[email protected]",
"destination": "wwwroot/lib/bootstrap",
"files": [
"js/bootstrap.bundle.js",
"css/bootstrap.min.css"
]
},
{
"library": "[email protected]",
"destination": "wwwroot/lib/jquery",
"files": [
"jquery.min.js"
]
}
]
}
Try Libman, it's as simple as Bower and you can specify wwwroot/lib/ as the download folder.
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.
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.
We use bootstrap 4 in asp.net core but reference the libraries from "npm" using the "Package Installer" extension and found this to be better than Nuget for Javascript/CSS libraries.
We then use the "Bundler & Minifier" extension to copy the relevant files for distribution (from the npm node_modules folder, which sits outside the project) into wwwroot as we like for development/deployment.
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.
Source: Stackoverflow.com