【问题标题】:Method not found error when using BundleTransformer in MVC4在 MVC4 中使用 BundleTransformer 时找不到方法错误
【发布时间】:2013-07-10 21:20:21
【问题描述】:

我们在 MVC3 应用程序中使用 LESS 代码捆绑,一切正常。 在我们的 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)、BundleTransfomer: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.IEnumerable1<System.IO.FileInfo> System.Web.Optimization.BundleResponse.get_Files()'.]
BundleTransformer.Core.Transformers.TransformerBase.Process(BundleContext context, BundleResponse response) +0
System.Web.Optimization.Bundle.ApplyTransforms(BundleContext context, String 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 step, Boolean& completedSynchronously) +165

有什么建议我应该检查什么?或者如何让 LESS 捆绑在 MVC4 下工作?

【问题讨论】:

    标签: asp.net-mvc-4 less bundling-and-minification


    【解决方案1】:

    我遇到了同样的问题,我找到了解决方案:) 这个问题是由 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();
                }
    

    一切正常。 链接到正确的课程:https://gist.github.com/gr4b4z/8349097

    【讨论】:

      【解决方案2】:

      虽然乍一看这似乎是一个不同的问题,但这篇文章解决了我的问题: ASP.NET MVC4 App fails to compile Bootstrap.LESS on production while it works on dev

      这两种情况的根本原因是相同的。显然,在 MVC4 捆绑中使用虚拟路径,并且用于正确解析的 LESS 导入现在无法找到依赖文件。

      【讨论】:

        【解决方案3】:

        只是 BundleTransformer.Core 1.6.28 与 Microsoft ASP.NET Web Optimization Framework 1.1.0 不兼容。这时候就需要使用BundleTransformer.Core 1.7.12 Beta 1或者等待1.7.16版本发布。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-07-07
          • 1970-01-01
          • 2015-08-19
          • 1970-01-01
          • 2014-09-24
          • 2021-05-07
          相关资源
          最近更新 更多