gpt4 book ai didi

asp.net-mvc - 在 asp.net mvc 中升级到 bootstrap 4 CSS minifier 中断

转载 作者:行者123 更新时间:2023-12-05 01:04:48 34 4
gpt4 key购买 nike

这些是我产生这个错误所遵循的步骤

检查 VS 2017 是否是最新的

VS version

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

更改 web.config 以通过更改 debug = false 来缩小和捆绑

<compilation debug="false" targetFramework="4.6.1"/>

F5 -> 查看站点,我看到一个 CSS 文件,其中的内容被缩小了。

停止调试

从 VS -> Tools -> NuGet Package Manger -> Manage NuGet Packages 获取解决方案。

我看到 14 个更新,其中一个是我们想在项目中使用的 bootstrap v4。更新所有包

包更新后F5不调试

查看源码 -> CSS 文件被打包成一个文件 -> 查看 CSS 文件,你会看到一个错误

/* Minification failed. Returning unminified contents.
(6,10): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,25): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,42): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,59): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,74): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,88): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,105): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,122): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,138): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,153): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,168): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,181): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,196): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,216): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,234): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,254): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,272): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,287): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,305): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,322): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,338): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,353): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,371): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,393): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,415): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,437): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,460): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,644): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
*/

根据这个post该问题已在 BundlerMinifier 中修复,但我没有那个包或 Nuglify,缩小和捆绑似乎仍然发生。

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

我在这里错过了什么?

最佳答案

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

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;
}
}

现在你可以添加一个新的Bundle

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

关于asp.net-mvc - 在 asp.net mvc 中升级到 bootstrap 4 CSS minifier 中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52207265/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com