Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在asp.net mvc中升级到bootstrap 4 CSS迷你程序中断_Asp.net Mvc - Fatal编程技术网

Asp.net mvc 在asp.net mvc中升级到bootstrap 4 CSS迷你程序中断

Asp.net mvc 在asp.net mvc中升级到bootstrap 4 CSS迷你程序中断,asp.net-mvc,Asp.net Mvc,以下是我产生此错误所遵循的步骤 检查VS 2017是否为最新版本 创建了一个新的asp.net web应用程序,选择了MVC和F5来调试应用程序,而不做任何更改。我看到不同的CSS文件没有捆绑或缩小 通过更改debug=false,在web.config中进行更改以缩小并绑定 <compilation debug="false" targetFramework="4.6.1"/> 根据这一点,BundlerMinifier解决了这个问题,但我没有这个包或Nuglify和minif

以下是我产生此错误所遵循的步骤

检查VS 2017是否为最新版本

创建了一个新的asp.net web应用程序,选择了MVC和F5来调试应用程序,而不做任何更改。我看到不同的CSS文件没有捆绑或缩小

通过更改debug=false,在web.config中进行更改以缩小并绑定

<compilation debug="false" targetFramework="4.6.1"/>
根据这一点,BundlerMinifier解决了这个问题,但我没有这个包或Nuglify和minification,捆绑似乎仍然在发生

开箱即用而不做任何更改应该是直截了当的,但事实并非如此

我在这里遗漏了什么?

这是一个内置的C#问题。他们使用自己的类来压缩css。我找到了解决问题的方法。你必须创建自己的类

public class MyStyleBundle : Bundle
{
    public MyStyleBundle(string virtualPath) : base(virtualPath, new MyCssMinify())
    {
    }

    public MyStyleBundle(string virtualPath, string cdnPath) : base(virtualPath, cdnPath, new MyCssMinify())
    {
    }
}

public class MyCssMinify : IBundleTransform
{
    internal static readonly MyCssMinify Instance = new MyCssMinify();

    internal static string CssContentType = "text/css";


    public virtual void Process(BundleContext context, BundleResponse response)
    {
        if (context == null)
        {
            throw new ArgumentNullException("context");
        }
        if (response == null)
        {
            throw new ArgumentNullException("response");
        }
        if (!context.EnableInstrumentation)
        {
            // CssCompress.Go- This is your CSS compression implementation
            // You can use the library " Uglify"
            response.Content = CssCompress.Go(response.Content);
        }
        response.ContentType = CssContentType;
    }
}
现在,您可以添加一个新包

    bundles.Add(new MyStyleBundle("~/Content/css").Include(
              "~/Content/bootstrap.css",
              "~/Content/site.css"));

如果您没有使用任何特殊的Bootstrap 4编码,请转到nugget并选择Bootstrap的第4版之前版本。

请使用正确的语法并详细说明您的答案。
    bundles.Add(new MyStyleBundle("~/Content/css").Include(
              "~/Content/bootstrap.css",
              "~/Content/site.css"));