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

时间:2015-11-20 08:22:04

标签: 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()'.

at:

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:找不到方法:&#39; System.String Yahoo.Yui.Compressor.ICompressor.get_ContentType()&#39;。]                Yahoo.Yui.Compressor.Web.Optimization.YuiCompressorTransform.Process(BundleContext context,BundleResponse response)+0        System.Web.Optimization.Bundle.ApplyTransforms(BundleContext context,String bundleContent,IEnumerable 1 bundleFiles) +273 System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext context) +141 System.Web.Optimization.Bundle.GetBundleResponse(BundleContext context) +45 System.Web.Optimization.BundleResolver.GetBundleContents(String virtualPath) +166 System.Web.Optimization.AssetManager.EliminateDuplicatesAndResolveUrls(IEnumerable 1 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中的ASP._Page_Views_Shared__Layout_cshtml.Execute():8        System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+198        System.Web.Mvc.WebViewPage.ExecutePageHierarchy()+ 105        System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage)+90

1 个答案:

答案 0 :(得分:4)

2.7.0版中的IVsSolutionEvents3 nuget包具有不正确的依赖关系。它在版本2.0.0或更高版本中需要OnAfterProjectOpen。但是需要2.7.0版本。

YUICompressor.NET.Web.Optimization升级到版本2.7.0应修复它。