我正在跟踪一个示例,当为MVC项目创建自定义 bundle 时,无法使“NoTransform”正常工作。这是我的代码,由于“NoTransform”而产生错误,该代码无法显示,错误为“错误1找不到类型或 namespace 名称'NoTransform'(您是否缺少using指令或程序集引用?)” 。有什么想法吗?
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.WebPages;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace CoyleAzure
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
// Added to Add DisplayModes
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Phone")
{
ContextCondition = (context => (
(context.GetOverriddenUserAgent() != null) &&
(
(context.GetOverriddenUserAgent().IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) ||
(context.GetOverriddenUserAgent().IndexOf("iPod", StringComparison.OrdinalIgnoreCase) >= 0) ||
(context.GetOverriddenUserAgent().IndexOf("Droid", StringComparison.OrdinalIgnoreCase) >= 0) ||
(context.GetOverriddenUserAgent().IndexOf("Blackberry", StringComparison.OrdinalIgnoreCase) >= 0) ||
(context.GetOverriddenUserAgent().StartsWith("Blackberry", StringComparison.OrdinalIgnoreCase))
)
))
});
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Tablet")
{
ContextCondition = (context => (
(context.GetOverriddenUserAgent() != null) &&
(
(context.GetOverriddenUserAgent().IndexOf("iPad", StringComparison.OrdinalIgnoreCase) >= 0) ||
(context.GetOverriddenUserAgent().IndexOf("Playbook", StringComparison.OrdinalIgnoreCase) >= 0) ||
(context.GetOverriddenUserAgent().IndexOf("Transformer", StringComparison.OrdinalIgnoreCase) >= 0) ||
(context.GetOverriddenUserAgent().IndexOf("Xoom", StringComparison.OrdinalIgnoreCase) >= 0)
)
))
});
IBundleTransform jsTransformer;
IBundleTransform cssTransformer;
#if DEBUG
jsTransformer = new NoTransform("text/javascript");
cssTransformer = new NoTransform("text/css");
#else
jsTransformer = new JsMinify();
cssTransformer = new CssMinify();
#endif
var
DesktopJSBundle = new Bundle("~/Scripts/DesktopJS", jsTransformer);
DesktopJSBundle.Include("~/Scripts/jquery-1.6.4. js");
DesktopJSBundle.Include("~/Scripts/jquery-ui-1.8.11. js");
DesktopJSBundle.Include("~/Scripts/jquery.unobtrusive-ajax.js");
DesktopJSBundle.Include("~/Scripts/jquery.validate.js");
DesktopJSBundle.Include("~/Scripts/jquery.validate.unobtrusive.js");
BundleTable.Bundles.Add(DesktopJSBundle);
var DesktopCSSBundle = new Bundle("~/Content/DesktopCSS", cssTransformer);
DesktopCSSBundle.Include("~/Content/Site.css");
BundleTable.Bundles.Add(DesktopCSSBundle);
var MobileJSBundle = new Bundle("~/Scripts/MobileJS", jsTransformer);
MobileJSBundle.Include("~/Scripts/jquery-1.6.4.js");
MobileJSBundle.Include("~/Scripts/jquery.mobile-1.1.0.js");
BundleTable.Bundles.Add(MobileJSBundle);
var MobileCSSBundle = new Bundle("~/Content/MobileCSS", cssTransformer);
MobileCSSBundle.Include("~/Content/jquery.mobile-1.1.0.css");
MobileCSSBundle.Include("~/Content/jquery.mobile.structure-1.1.0.css");
BundleTable.Bundles.Add(MobileCSSBundle);
//BundleTable.Bundles.RegisterTemplateBundles();
BundleTable.Bundles.EnableDefaultBundles();
}
//BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
最佳答案
NoTransform
类不再需要公开,因为从RC开始,Transform
上的空Bundle
类隐式意味着NoTransform
。
前:
new Bundle("~/yourbundle", new NoTransform())
现在:
new Bundle("~/yourbundle")
我们认为不需要虚拟实例更干净。我们将其保留在内部是因为它有一点逻辑可能会引起一些麻烦,因为Transform负责为响应设置contentType。默认逻辑使用包中第一个文件的文件扩展名(.js/.css)。
同样,通过添加脚本/样式渲染帮助器,您不再需要基于debug = true | false在不同的转换之间动态切换。 helper 应该为您照顾好这件事。
关于asp.net - 尝试创建新 bundle 时NoTransform不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11004803/