Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoTransform isn't working when trying to create new Bundle

I am following an example and cannot get the "NoTransform" to work when creating a custom bundle for an MVC project. Here is my code that won't compile because of the "NoTransform" yielding an error that says, "Error 1 The type or namespace name 'NoTransform' could not be found (are you missing a using directive or an assembly reference?)". Any thoughts?

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);




    }
}
like image 862
macecase Avatar asked Jun 12 '12 21:06

macecase


4 Answers

The NoTransform class no longer needs to be public because starting in RC, a null Transform class on Bundle implicitly means NoTransform.

Before:

new Bundle("~/yourbundle", new NoTransform())

Now:

new Bundle("~/yourbundle")

We felt it was cleaner to not require a dummy instance. We kept it internal because it has a tiny bit of logic that would potentially cause some trouble, since the Transform is responsible for setting the contentType for the response. The default logic uses the file extension of the first file in your bundle (.js/.css).

Also with the addition of the Script/Styles Render helpers, you should no longer need to dynamically switch between different transforms based on debug=true|false. The helpers should take care of that for you.

like image 190
Hao Kung Avatar answered Nov 15 '22 22:11

Hao Kung


not a direct answer to this but just to point it out to anyone who comes across this in the furture... it can be done via config as well, (see https://stackoverflow.com/a/12605451/6486)

<system.web>
    <compilation debug="true" />
    <!-- Lines removed for clarity. -->
</system.web>
like image 30
Jon Avatar answered Nov 15 '22 22:11

Jon


This code is from MVC 4 Beta (or more precisely System.Web.Optimization beta1) but you are probably trying to compile it with MVC 4 RC (or more precisely System.Web.Optimization beta2) (if MVC 4 at all). In MVC 4 RC NoTransform is internal.

like image 3
Pol Avatar answered Nov 15 '22 21:11

Pol


The NoTransform and other methods like Scripts, Styles.. are the new features of bundling and minification that is available in the MVC 4 beta and MVC 4 RC versions. I hope you are not using the proper version of ASP.NET MVC and hence you are getting the compilation errors.

http://blog.kurtschindler.net/post/disabling-bundling-and-minification-in-aspnet-45mvc-4

like image 1
VJAI Avatar answered Nov 15 '22 22:11

VJAI