在 WebForms 中调试时关闭捆绑/缩小 [英] Turn off bundling/minification while debugging in WebForms
问题描述
我希望能够在生产环境中缩小/捆绑我的 javascript 文件,同时在本地调试时将它们解压缩/解开;但是,VS2012 中的默认 WebForms 站点似乎不允许这样做.
I want to be able to minify/bundle my javascript files in a production environment while having them unminified/unbundled when debugging locally; however, the default WebForms site in VS2012 does not appear to allow for it.
重现我的问题的步骤:
- 创建一个新的ASP.NET Web 窗体应用程序"(在我的例子中是 c#)
- 无需调试即可启动并在浏览器中查看资源
- 注意未缩小的 jquery/modernizr 文件,但捆绑/缩小了
MsAjaxJS
和WebFormsJs
web.config,默认有:
web.config, by default has:
<compilation debug="true" targetFramework="4.5">
我什至尝试通过明确告诉 BundleTable
不要优化来修改 Global.asax:
And I've even tried modifying the Global.asax by explicitly telling BundleTable
not to optimize:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
BundleTable.EnableOptimizations = false;
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterOpenAuth();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
然而,我仍然得到无法调试的 javascript 文件:
Yet, I still get undebuggable javascript files:
这个网站(我意识到是for MVC) 告诉我 web.config 中的 debug="true"
或 Global.asax 中的 BundleTable.EnableOptimizations = false;
应该关闭该功能.和 这个网站(是用于WebForms,并且从第一个链接开始),没有提到将其关闭以进行调试.
This site (which I realize is for MVC) tells me that either debug="true"
in the web.config or BundleTable.EnableOptimizations = false;
in Global.asax should turn off the functionality. And this site, (which is for WebForms and is linked from the first), doesn't mention turning it off for debugging.
当 debug="false" 时,我如何(干净地)告诉我的项目仅缩小/捆绑?
How might I (cleanly) tell my project to only minify/bundle when debug="false"?
(我使用的是 ASP.NET 4.5)
(I'm using ASP.NET 4.5)
这个问题 和 这个问题 很相似,但它们都只是使用 Scripts.Render()
提供解决方案.有没有办法通过使用 ScriptManager 的模板化方法来实现这一点?
This question and this question are similar, but they both only offer a solution using Scripts.Render()
. Is there a way to accomplish this with the templated method of using the ScriptManager?
推荐答案
将以下代码添加到 Application_Start 方法中的 Global.asax.cs 文件中.这对我来说非常有效.
Add the following code to your Global.asax.cs file in the Application_Start method. This works perfectly for me.
#if DEBUG
foreach (var bundle in BundleTable.Bundles)
{
bundle.Transforms.Clear();
}
#endif
这篇关于在 WebForms 中调试时关闭捆绑/缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!