在Visual Studio中手动安装Bootstrap [英] Manually Install Bootstrap in Visual Studio

查看:189
本文介绍了在Visual Studio中手动安装Bootstrap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bower显然无法再将Bootstrap安装到Visual Studio项目中:

Bower apparently does not work for installing Bootstrap into a Visual Studio project any more:

https://developercommunity .visualstudio.com/content/problem/134643/bootstrap-can-be-installed-via-bower.html

我正在Visual Studio 15.4中进行ASP.Net Core 2 MVC项目.

I am doing an ASP.Net Core 2 MVC project in Visual Studio 15.4.

对我来说似乎很简单,我只需下载Bootstrap并将其放在我的项目中,然后以正常方式使用链接标记从视图中引用bootstrap.css文件.

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-4.0.0-alpha.6.dist并将其放置在项目的wwwroot文件夹中.该文件夹绝对已解压缩,并且在我认为的位置.在下一级是一个名为css的文件夹,该文件夹中包含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.

然后我有一个普通的看法,像这样:

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>

似乎页面无法找到样式表.当我运行项目时,没有应用Bootstrap类.当我单击页面的查看源代码"选项并单击样式表的地址时,它确实告诉我找不到样式表:

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:

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.

我在Visual Studio之外使用普通文本文件执行了此操作,并使其正常工作.关于MVC视图如何解析样式表的位置,我肯定有些不明白.

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.

有人知道我在做什么错吗,或者有更好的方法来解决此问题?

Does anyone know what I'm doing wrong, or else a better approach to a workaround for the issue?

推荐答案

最简单的方法是使用NuGet控制台.

The simplest way is to use the NuGet console.

只需导航至:

打开VS >>工具菜单>> NuGet软件包管理器>>控制台命令.

或者:选项>> 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.

这篇关于在Visual Studio中手动安装Bootstrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆