这些是我要产生此错误的步骤
检查VS 2017是否为最新
创建一个新的asp.net Web应用程序,选择MVC和F5来调试该应用程序,而无需进行任何更改。我看到了未捆绑或缩小的不同CSS文件。
更改web.config以通过更改debug = false来缩小和捆绑
<compilation debug="false" targetFramework="4.6.1"/>
F5->查看站点,我看到一个CSS文件,其中的内容已缩小。
停止调试
从VS->工具-> NuGet软件包管理器->管理NuGet软件包以获取解决方案。
我看到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,并且缩小和捆绑似乎仍然发生。
直接进行此操作而不进行任何更改应该是直接的,但事实并非如此。
我在这里想念什么?
答案 0 :(得分:1)
这是内置的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"));
答案 1 :(得分:0)
如果您没有使用任何特殊的Bootstrap 4编码,请转至选择一个Bootstrap的4版之前的版本。