首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MvcBundleConfig minify="false“问题

MvcBundleConfig minify="false“问题
EN

Stack Overflow用户
提问于 2014-02-27 03:04:15
回答 1查看 424关注 0票数 3

我正在使用Tom DuPonts MvcBundler,遵循他的指南:http://www.tomdupont.net/2012/03/configuring-bundles-in-mvc-4.html

我在我的配置文件中有这个

代码语言:javascript
复制
<add bundlePath="~/js/shared" minify="false">
  <directories>
    <add directoryPath="~/Scripts/Shared" searchPattern="*.js"></add>
  </directories>
</add>

这将抛出此错误

代码语言:javascript
复制
Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 59:     @Html.JsBundle("~/js/types")
Line 60:     @Html.JsBundle("~/js/libraries")
Line 61:     @Html.JsBundle("~/js/shared")   <-------- Offending line

删除

代码语言:javascript
复制
minify="false"

或更新为

代码语言:javascript
复制
minify="true"

允许应用程序正常工作。

有没有办法不对使用此扩展名的一组文件使用缩小?

全栈跟踪

代码语言:javascript
复制
[NullReferenceException: Object reference not set to an instance of an object.]
   System.Object.GetType() +0
   System.Web.Optimization.DefaultBundleBuilder.BuildBundleContent(Bundle bundle, BundleContext context, IEnumerable`1 files) +381
   System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext context) +282
   System.Web.Optimization.Bundle.GetBundleUrl(BundleContext context, Boolean includeContentHash) +66
   System.Web.Mvc.HtmlHelperExtensions.ReferenceBundle(HtmlHelper helper, String bundlePath, TagBuilder baseTag, String key) +142
   ASP._Page_Views_Shared_Layouts_Default__Layout_cshtml.Execute() in Web\Views\Shared\Layouts\Default\_Layout.cshtml:61
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
   System.Web.WebPages.WebPageBase.Write(HelperResult result) +89
   System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +233
   System.Web.WebPages.WebPageBase.PopContext() +291
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
   System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +240
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

编辑:

在将库更新到2.2.0之后,我现在得到这个错误

代码语言:javascript
复制
Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper<dynamic>' 
does not contain a definition for 'CssBundle' and no extension method
'CssBundle' accepting a first argument of type 
'System.Web.Mvc.HtmlHelper<dynamic>' could be found (are you missing a 
using directive or an assembly reference?)

Line 19:     <link rel="icon" href="/Content/images/favicon.ico">
Line 20:     
Line 21:     @Html.CssBundle("~/css/bootstrap")
EN

回答 1

Stack Overflow用户

发布于 2014-02-27 13:55:07

这应该在v2.2.0 (https://www.nuget.org/packages/MvcBundleConfig/2.2.0)中修复

仅供参考:这个包太旧了,需要更新。我会尽快发布3.0版本,增加对Bundle Transformer的支持。(https://bundletransformer.codeplex.com/)

代码语言:javascript
复制
private static void AddBundleConfiguration<T>(BundleCollection bundles, IEnumerable<BundleConfig> bundleConfigs)
    where T : IBundleTransform, new()
{
    foreach (var bundleConfig in bundleConfigs)
    {
        // The bug WAS here; it was passing in null instead of an empty array, thus the
        // Bundle constructor params would have an array of one that contained a null.
        var transform = bundleConfig.Minify
            ? new IBundleTransform[] { new T() }
            : new IBundleTransform[0];

        var bundle = String.IsNullOrWhiteSpace(bundleConfig.CdnPath)
            ? new Bundle(bundleConfig.BundlePath, transform)
            : new Bundle(bundleConfig.BundlePath, bundleConfig.CdnPath, transform);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22050807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档