我用MVC 5创建了我的第一个网站,它在我的本地机器上运行良好,但当我将其发布到服务器时,一些CSS没有正确缩小.

    /* Minification failed. Returning unminified contents.
    (80,1): run-time error CSS1019: Unexpected token, found '@import'
    (80,9): run-time error CSS1019: Unexpected token, found 'url('../Content/dark-skin/skin.css')'
    (671,16): run-time error CSS1062: Expected semicolon or closing curly-brace, found ':'
    (1288,16): run-time error CSS1062: Expected semicolon or closing curly-brace, found ':'
    (1680,1): run-time error CSS1019: Unexpected token, found '@keyframes'
    (1682,5): run-time error CSS1062: Expected semicolon or closing curly-brace, found '50%'
    (1685,1): run-time error CSS1019: Unexpected token, found '@-webkit-keyframes'
    (1687,5): run-time error CSS1062: Expected semicolon or closing curly-brace, found '50%'
     */
    /* NUGET: BEGIN LICENSE TEXT
     *
     * Microsoft grants you the right to use these script files for the sole
     * purpose of either: (i) interacting through your browser with the Microsoft
     * website or online service, subject to the applicable licensing or use
     * terms; or (ii) using the files as included with a Microsoft product subject
     * to that product's license terms. Microsoft reserves all other rights to the
     * files not expressly granted by Microsoft, whether by implication, estoppel
     * or otherwise. The notices and licenses below are for informational purposes only.
     *
     * NUGET: END LICENSE TEXT */
    /*!
     * Bootstrap v3.0.0
     *
     * Copyright 2013 Twitter, Inc
     * Licensed under the Apache License v2.0
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Designed and built with all the love in the world by @mdo and @fat.
     *//*! normalize.css v2.1.0 | MIT License | git.io/normalize */

在try 更正一些错误并再次发布后,错误看起来是一样的.

最奇怪的是,为了网站的目的,我稍微修改了bootstrap.css个.当我发布它时,更改不在Bundle 文件中.是否有可能 bootstrap 是从 bootstrap 服务器加载的,而不是我的项目?

    bundles.Add(new StyleBundle("~/Content/cssmain").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css",
                      "~/Content/ilightbox.css",
                      "~/Content/bannerscollection_zoominout.css"));

我也试着自己使用Web应用程序进行缩小,但我的更改看不到,文件似乎也没有缩小.

感谢您的帮助.

推荐答案

我通过做两件事解决了Bundle bootstrap.css的问题:

  1. 包括 bootstrap .css first在Bundle 包中.问题中的代码示例已经做到了这一点,但我没有做到.
  2. official minified version(bootstrap.min.css)添加到与未统一版本相同的目录中的项目中.这会提示绑定器使用现有的缩小文件,而不是try (但失败)缩小 bootstrap .css本身.请参见下面屏幕截图中的绿色箭头.

请注意,如果您使用的是特定主题,请替换 bootstrap .css和 bootstrap .min.css与主题提供的文件.以下是我的项目中使用spacelab主题的工作代码:

            bundles.Add(new StyleBundle(GetStyleBundlePath("bootstrap")).Include(
            "~/Content/3rdParty/bootstrap.spacelab.css",
            "~/Content/3rdParty/bootstrap-datepicker.css",
            "~/Content/3rdParty/bootstrap-multiselect.css"));

在此处输入图像描述

Asp.net相关问答推荐

AJAX返回未定义、失败

DataTables-如何修改来自JSON响应或其他DataTables参数的无结果(ZeroRecords)消息

为什么 @Html.EditorFor 和 @Html.PasswordFor 在 MVC 中创建不同的样式框?

如何在 C#/MVC 4 中的 Html.TextBoxFor 中输入占位符文本

单个方法(即扩展方法)之间的调用不明确

逐步 ASP.NET 自动构建/部署

从 asp.net 中的 Web.config 获取连接字符串

如何向 Array.IndexOf 添加不区分大小写的选项

ASP.NET 如何将控件呈现为 HTML?

登录成功后 User.Identity.IsAuthenticated 为 false

Anti-Forgery Token 适用于不同的基于声明的用户

测试项目中的 App.config

.NET 核心 IdentityUser 模型中规范化邮箱和用户名的用途是什么?

如何从 Asp.net Mvc-3 发送邮箱?

如何使用 WebRequest 发布数据并从网页获取响应

如何忽略身份框架的魔力,只使用 OWIN 身份验证中间件来获取我寻求的声明?

MVC3 值 Ajax 文件上传

避免在 ASP.NET MVC 中使用会话状态是一种好习惯吗?如果是,为什么以及如何?

asp.net core 2.0 - 值不能为空.参数名称:连接字符串

强制 IIS Express 进入classic 管道模式