How to use Bootstrap in an ASP.Net Core 2.0 Application?

吃可爱长大的小学妹 提交于 2019-12-21 17:25:26

问题


I know that Bower is not recommended to be used with ASP.Net Core 2.0. Instead, I used NuGet to download Bootstrap dependency into my project. Therefore, I can't reference the files in my Layout view like I used to do with Bower using:

<link href="~/lib/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />

I am trying to use NuGet to get a cleaner code. However, I can't seem to be able to reference this package in my project. Anyone has an idea how to use/reference bootstrap installed through NuGet in an ASP.Net Core 2.0 application?


回答1:


In .NET Core, Nuget is no longer suitable for deploying client files. This was a design decision made by Microsoft. Instead, you can use any of a host of client build/deploy tools like npm, or my preference is to simply link to the libraries you need st a CDN location. This eliminates deployment issues and offers better performance for your users.




回答2:


In Visual Studio 2017 Preview, you can use Library Manager:

Library Manager (“LibMan” for short) is Visual Studio’s experimental client-side library acquisition tool. It provides a lightweight, simple mechanism that helps users find and fetch library files from an external source (such as CDNJS) and place them in your project.

Soon it will available in VS stable version.




回答3:


Add the "Package Installer" and "Bundler & Minifier" Extensions into Visual Studio (both created by Mads Kristensen)

Use the Package Installer to install client libraries using "npm" which is widely supported.

This downloads the files to a node_modules folder in the root of your web project.

Use Bundler & Minifier to copy/bundle/minify as you like for dev and/ or production from the node_modules folder to where you want them in the wwwroot folder.




回答4:


First, install a nmp configuration file, and add bootstrap like in bower.json and save. Visual studio will download it. This is available for all packages. You can find the installed packages in the nmp node under the dependencies node of your project. Find more informations here



来源:https://stackoverflow.com/questions/50071613/how-to-use-bootstrap-in-an-asp-net-core-2-0-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!