twitter-bootstrap 在 Visual Studio 中手动安装 Bootstrap
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47064657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Manually Install Bootstrap in Visual Studio
提问by Scitosol
Bower apparently does not work for installing Bootstrap into a Visual Studio project any more:
Bower 显然不再适用于将 Bootstrap 安装到 Visual Studio 项目中:
I am doing an ASP.Net Core 2 MVC project in Visual Studio 15.4.
我正在 Visual Studio 15.4 中做一个 ASP.Net Core 2 MVC 项目。
It seemed simple enough to me that I would just download Bootstrap and drop it in my project, then reference the bootstrap.css file from my views in the normal manner using the link tag.
对我来说似乎很简单,我只需下载 Bootstrap 并将其放入我的项目中,然后使用链接标记以正常方式从我的视图中引用 bootstrap.css 文件。
I downloaded bootstrap-4.0.0-alpha.6.dist and placed it in the wwwroot folder of my project. The folder is definitely unzipped and where I think it is. Down one level is a folder named css, and in this folder resides bootstrap.css.
我下载了 bootstrap-4.0.0-alpha.6.dist 并将其放在我项目的 wwwroot 文件夹中。该文件夹绝对已解压缩,我认为它在哪里。下一层是一个名为 css 的文件夹,该文件夹中存放着 bootstrap.css。
Then I have an ordinary view like this:
然后我有一个这样的普通视图:
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
<link rel="stylesheet" href="~/bootstrap-4.0.0-alpha.6-dist/css/bootstrap.css" />
</head>
<body>
<h3 class="text-center">Hello, World!</h3>
</body>
</html>
And it seems that the page cannot locate the stylesheet. When I run the project, the Bootstrap classes are not applied. And when I click on the View Source option for the page and click on the address for the stylesheet, it indeed tells me that it cannot find the stylesheet:
并且页面似乎找不到样式表。当我运行项目时,没有应用 Bootstrap 类。当我单击页面的查看源选项并单击样式表的地址时,它确实告诉我它找不到样式表:
No webpage was found for the web address: http://localhost:62732/bootstrap-4.0.0-alpha.6-dist/css/bootstrap.css
HTTP ERROR 404
I have tried every variation on the address that I can think of, such as:
我已经尝试了我能想到的地址的所有变化,例如:
<link rel="stylesheet" href="../wwwroot/bootstrap-4.0.0-alpha.6-dist/css/bootstrap.css" />
but to no effect. I have also gotten this result in three different browsers.
但没有效果。我也在三种不同的浏览器中得到了这个结果。
I did this outside of Visual Studio with ordinary text files and got it to work. There must be something I don't understand about how MVC views resolve the locations of stylesheets.
我在 Visual Studio 之外使用普通文本文件完成了此操作并使其正常工作。关于 MVC 视图如何解析样式表的位置,我一定有什么不明白的地方。
Does anyone know what I'm doing wrong, or else a better approach to a workaround for the issue?
有谁知道我做错了什么,或者有更好的方法来解决这个问题?
回答by Sid Khanye
The simplest way is to use the NuGet console.
最简单的方法是使用 NuGet 控制台。
simply navigate to:
只需导航到:
Open VS >> Tools menu >> NuGet Package Manager >> Console Command.
打开 VS >> 工具菜单 >> NuGet 包管理器 >> 控制台命令。
Alternatively: Options >> NuGet Package Manager >> Package Sources dialog box.
或者:选项>> NuGet 包管理器>> 包源对话框。
Once the console appears at the bottom page, type:
控制台出现在底部页面后,键入:
PM> Install-Package bootstrap -Version 3.3.7
If this gives you any issues or helps, please let me know.
如果这给您带来任何问题或帮助,请告诉我。

