Asp.net mvc 4 在MVC4中使用BundleTransformer时未找到方法错误

Asp.net mvc 4 在MVC4中使用BundleTransformer时未找到方法错误,asp.net-mvc-4,less,bundling-and-minification,Asp.net Mvc 4,Less,Bundling And Minification,我们使用了代码较少的MVC3应用程序的捆绑,并且一切都正常工作。 在RegisterBundles()中,我们有如下代码: var bundle = new Bundle("~/assets/styles/EnhancedLayoutLess") .Include("~/assets/styles/enhanced-layout.less"); bundle.Transforms.Add(new CssTransformer()); BundleTable.Bundles.Add(bu

我们使用了代码较少的MVC3应用程序的捆绑,并且一切都正常工作。 在RegisterBundles()中,我们有如下代码:

var bundle = new
Bundle("~/assets/styles/EnhancedLayoutLess")
     .Include("~/assets/styles/enhanced-layout.less");
bundle.Transforms.Add(new CssTransformer());
BundleTable.Bundles.Add(bundle);
但是,在升级到MVC4和BundleTransformer:Core(1.6.28)、BundleTransformer:LESS(1.6.26)和Microsoft ASP.NET Web Optimization Framework(1.1.0)的最新版本后,当我们尝试检索捆绑包时,会出现以下错误:

找不到方法: 'System.Collections.Generic.IEnumerable'1 System.Web.Optimization.BundleResponse.get_Files()'

[MissingMethodException:未找到方法: 'System.Collections.Generic.IEnumerable
1
System.Web.Optimization.BundleResponse.get_Files()'。]
BundleTransformer.Core.Transformers.TransformerBase.Process(BundleContext 上下文,捆绑响应)+0
System.Web.Optimization.Bundle.ApplyTransforms(BundleContext, 字符串bundleContent,IEnumerable
1 bundleFiles)+198
System.Web.Optimization.Bundle.ProcessRequest(BundleContext) +269 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +913 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+165


有什么建议我应该检查什么?或者如何在MVC4下减少捆绑?

虽然乍看起来似乎是另一个问题,但这篇文章解决了我的问题:


两个病例的根本原因是相同的。显然,在MVC4中,捆绑使用了虚拟路径,而用于正确解析的导入较少,现在无法找到依赖文件。

我遇到了同样的问题,我找到了解决方案:) 这个问题是由YuiCompressorTransform类(Yahoo.Yui.Compressor.Web.Optimization)引起的

进程方法包含以下代码:

// Grab all of the content.
        var rawContent = new StringBuilder();
        foreach (var fileInfo in response.Files)
        {
            using (var reader = fileInfo.OpenText())
            {
                rawContent.Append(reader.ReadToEnd());
            }
        }
但是fileInfo没有OpenText方法

我已将此代码更改为以下代码:

using (var stream = fileInfo.VirtualFile.Open())
            {
                var streamReader = new StreamReader(stream);
                rawContent.Append(streamReader.ReadToEnd());
                streamReader.Close();
            }
一切正常。 指向正确类的链接:

只是该类与Microsoft ASP.NET Web优化框架1.1.0不兼容。当时,有必要使用或等待版本的发布