相关疑难解决方法(0)

ASP.NET Bundles如何禁用缩小

我有debug="true"我的web.config(s),我只是不希望我的捆绑缩小,但我做的任何事情似乎都禁用它.我试过了enableoptimisations=false,这是我的代码:

//Javascript
bundles.Add(new ScriptBundle("~/bundles/MainJS")
            .Include("~/Scripts/regular/lib/mvc/jquery.validate.unobtrusive.js*")
            .Include("~/Scripts/regular/lib/mvc/jquery.validate*")
            .Include("~/Scripts/regular/lib/bootstrap.js")
            .IncludeDirectory("~/Scripts/regular/modules", "*.js", true)
            .IncludeDirectory("~/Scripts/regular/pages", "*.js", true)
            .IncludeDirectory("~/Scripts/regular/misc", "*.js", true));

//CSS
bundles.Add(new StyleBundle("~/bundles/MainCSS")
            .Include("~/Content/css/regular/lib/bootstrap.css*")
            .IncludeDirectory("~/Content/css/regular/modules", "*.css", true)
            .IncludeDirectory("~/Content/css/regular/pages", "*.css", true))
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc bundle asp.net-mvc-4 asp.net-optimization

180
推荐指数
11
解决办法
14万
查看次数

打开发布模式时捆绑不在MVC5中工作

我在BundleConfig.cs中配置了以下捆绑包:

bundles.Add(new StyleBundle("~/bundles/css").Include(
                      "~/assets/bootstrap/css/bootstrap.css",
                      "~/assets/css/global/all.css"));
Run Code Online (Sandbox Code Playgroud)

我使用以下内容引用它:

@Styles.Render("~/bundles/css")
Run Code Online (Sandbox Code Playgroud)

当我处于调试模式(web.config编译debug="true")时,它按预期工作,因为它将两个css文件呈现为正常,即:

<link href="/assets/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="/assets/css/global/all.css" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)

但是,当我设置debug="false"上述行为仍然发生时,它确实识别文件,但它只是正常渲染它们.

为了确认捆绑绝对可行,我已经在BundleConfig中启用了优化,即 BundleTable.EnableOptimizations = true;

每当我执行上述操作时,它会捆绑css并按预期显示,即:

<link href="/bundles/css?v=WBKHkZAJly7jUzHrVDT8SwfaQE-CA9dbOUQUlLKadNE1" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)

编辑:

有些人提到将以下代码添加到我的BundleConfig.cs文件中将实现我的目标:

#if DEBUG
            BundleTable.EnableOptimizations = false;
#else
            BundleTable.EnableOptimizations = true;
#endif
Run Code Online (Sandbox Code Playgroud)

我理解并欣赏这个响应,但根据文档,MVC捆绑的默认行为是在发布模式下捆绑但不在调试模式下捆绑.我不明白为什么我应该添加额外的代码来使它在它应该已经完成​​时执行此操作.

编辑2

我忏悔了.事实证明我打开了Views文件夹中的web.config而不是主web.config.我更改了主web.config中的设置,这对我来说很好.我责怪ReSharper

.net css c# asp.net-mvc bundling-and-minification

30
推荐指数
4
解决办法
2万
查看次数