我正在尝试在我的项目中使用 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(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: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/