asp.net - YUICompressor.NET 找不到方法 ICompressor.get_ContentType() 错误

标签 asp.net minify yui-compressor

我正在尝试在我的项目中使用 YUICompressor.NET。这是一个asp.net mvc web项目,框架4.5.1。

我收到此错误:

Method not found: 'System.String Yahoo.Yui.Compressor.ICompressor.get_ContentType()'.

在:

Line 6:      <title>@ViewBag.Title - My ASP.NET Application</title>
Line 7:      @Styles.Render("~/Content/css")
Line 8:      @Scripts.Render("~/bundles/modernizr")
Line 9:  

有人有想法吗?

我按照此视频 (https://www.youtube.com/watch?v=NSHGSbViMm8) 中的说明操作,并将 RegisterBundles 方法的内容更改如下:

var javascriptConfig = new JavaScriptCompressorConfig();
var javascriptTransform = new YuiCompressorTransform(javascriptConfig);

bundles.Add(new Bundle("~/bundles/jquery", javascriptTransform).Include(
            "~/Scripts/jquery-{version}.js"));

bundles.Add(new Bundle("~/bundles/jqueryval", javascriptTransform).Include(
            "~/Scripts/jquery.validate*"));

// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new Bundle("~/bundles/modernizr", javascriptTransform).Include(
            "~/Scripts/modernizr-*"));

bundles.Add(new Bundle("~/bundles/bootstrap", javascriptTransform).Include(
          "~/Scripts/bootstrap.js",
          "~/Scripts/respond.js"));

bundles.Add(new StyleBundle("~/Content/css").Include(
          "~/Content/bootstrap.css",
          "~/Content/site.css"));

这是堆栈跟踪:
[MissingMethodException:找不到方法:'System.String Yahoo.Yui.Compressor.ICompressor.get_ContentType()'。] Yahoo.Yui.Compressor.Web.Optimization.YuiCompressorTransform.Process(BundleContext上下文,BundleResponse响应)+0 System.Web.Optimization.Bundle.ApplyTransforms(BundleContext上下文,字符串bundleContent,IEnumerable1bundleFiles)+273 System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext上下文)+141 System.Web.Optimization.Bundle.GetBundleResponse(BundleContext上下文)+45 System.Web.Optimization.BundleResolver.GetBundleContents(字符串虚拟路径)+166 System.Web.Optimization.AssetManager.EliminateDuplicatesAndResolveUrls(IEnumerable1 refs)+296 System.Web.Optimization.AssetManager.DeterminePathsToRender(IEnumerable`1 Assets )+733 System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths) +35 System.Web.Optimization.Scripts.RenderFormat(String tagFormat, String[] paths) +105 System.Web.Optimization.Scripts.Render(String[] paths) +21 c:\Users\Entegral\Documents\Visual Studio 2013\Projects\WebApplication4\WebApplication4\Views\Shared_Layout.cshtml:8 中的 ASP._Page_Views_Shared__Layout_cshtml.Execute() System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage)+90

最佳答案

版本 2.7.0 中的 YUICompressor.NET.Web.Optimization nuget 包具有不正确的依赖项。它需要 2.0.0 或更高版本的 YUICompressor.NET。但需要2.7.0版本。

YUICompressor.NET 升级到版本 2.7.0 应该可以修复该问题。

关于asp.net - YUICompressor.NET 找不到方法 ICompressor.get_ContentType() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33821994/

相关文章:

c# - 如何在 asp.net mvc 中为我的存储库制作无类型界面?

asp.net - 请求经常超时

php - 如何让 PHP 压缩 JS 和 CSS 代码?

asp.net - Yahoo.Yui.Compressor.Build.MsBuild.dll。无法加载文件或程序集“Yahoo.Yui.Compressor”

asp.net - 如何为 select 语句 where 列 IN 编写查询

c# - 无法将类型 'T' 隐式转换为 'T

javascript - 使用 Google App Engine 使用精简的 JS 构建网站以进行调试和生产

msbuild - 在 Azure Project 上缩小并包含 js 和 css 文件

javascript - 使用 YUIcompressor 压缩 JavaScript 时跳过许可证/信用评论

java - PHP:执行 Yuicompressor.jar 太慢了