This project has moved. For the latest updates, please go here.

SCSS File Not Preprocessed When EnableOptimizations is False

Jan 28, 2014 at 7:50 PM
I am trying to bundle Sass files along with standard css files. In our development environment, we don't want to enable optimizations in order to make it easier to debug problems and work with un-minimized css. However, when I set the EnableOptimizations flag to false, the browser is sent the original scss file without any preprocessing done. Am I missing something in the config?
    public static void Register(BundleCollection bundles)
    {
        var commonStylesBundle = new Bundle("~/bundles/styles/common")
            .Include("~/media/css/standard.css")
            .Include("~/media/css/test.scss");
        commonStylesBundle.Builder = new NullBuilder();
        commonStylesBundle.Transforms.Add(new CssTransformer());
        commonStylesBundle.Orderer = new NullOrderer();

        bundles.Add(commonStylesBundle);

        BundleTable.EnableOptimizations = false; // Set to true, things work
        BundleTable.Bundles.UseCdn = false;
    }
Coordinator
Jan 29, 2014 at 6:54 AM
Hello, Jdecock!

What the mode are running IIS: Integrated or Classic?

If in the classic mode, then you need to add the settings, that described in the documentation.
Jan 29, 2014 at 2:49 PM
I'm not actually using IIS. I'm using the Visual Studio Development Server in Visual Studio 2012. It's a ASP.Net Web Application using .NET 4.5.
Coordinator
Jan 29, 2014 at 2:54 PM
Send me your Web.config file.
Jan 29, 2014 at 3:24 PM
I had to make some changes to the web.config before posting it, but I hopefully haven't changed anything that would have any effect on this issue:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="bundleTransformer">
            <section name="core" type="BundleTransformer.Core.Configuration.CoreSettings, BundleTransformer.Core" />
            <section name="sassAndScss" type="BundleTransformer.SassAndScss.Configuration.SassAndScssSettings, BundleTransformer.SassAndScss" />
            <section name="microsoftAjax" type="BundleTransformer.MicrosoftAjax.Configuration.MicrosoftAjaxSettings, BundleTransformer.MicrosoftAjax" />
        </sectionGroup>
    </configSections>
    <appSettings />
    <connectionStrings>
        <add name="Repository" connectionString="Data Source=localhost;Initial Catalog=MyDatabase;User Id=username;Password=password;" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <pages maintainScrollPositionOnPostBack="false" controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">
            <namespaces />
            <controls />
        </pages>
        <compilation defaultLanguage="C#" debug="true" numRecompilesBeforeAppRestart="15" targetFramework="4.5">
            <assemblies />
        </compilation>
        <authentication mode="Forms">
            <forms name="MyApp.uth" loginUrl="login.aspx" defaultUrl="~/Account.aspx" timeout="30" slidingExpiration="true" />
        </authentication>
        <customErrors mode="Off" redirectMode="ResponseRewrite" defaultRedirect="~/application-error.aspx">
            <error statusCode="404" redirect="~/page-not-found.aspx" />
        </customErrors>
        <sessionState mode="StateServer" timeout="35" />
        <globalization uiCulture="en-US" culture="en-US" requestEncoding="utf-8" responseEncoding="utf-8" />
        <trace enabled="false" requestLimit="10" pageOutput="true" traceMode="SortByTime" localOnly="true" />
        <xhtmlConformance mode="Transitional" />
        <httpModules />
    </system.web>
    <system.net>
        <mailSettings>
            <smtp>
                <network host="127.0.0.1" port="25" />
            </smtp>
        </mailSettings>
    </system.net>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true" />
        <handlers>
            <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
            <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
            <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
            <add name="SassAssetHandler" path="*.sass" verb="GET" type="BundleTransformer.SassAndScss.HttpHandlers.SassAndScssAssetHandler, BundleTransformer.SassAndScss" resourceType="File" preCondition="" />
            <add name="ScssAssetHandler" path="*.scss" verb="GET" type="BundleTransformer.SassAndScss.HttpHandlers.SassAndScssAssetHandler, BundleTransformer.SassAndScss" resourceType="File" preCondition="" />
        </handlers>
        <httpErrors errorMode="Custom">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/page-not-found.aspx" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
    <bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd">
        <core>
            <css defaultMinifier="NullMinifier">
                <minifiers>
                    <add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" />
                    <add name="MicrosoftAjaxCssMinifier" type="BundleTransformer.MicrosoftAjax.Minifiers.MicrosoftAjaxCssMinifier, BundleTransformer.MicrosoftAjax" />
                </minifiers>
                <translators>
                    <add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" />
                    <add name="SassAndScssTranslator" type="BundleTransformer.SassAndScss.Translators.SassAndScssTranslator, BundleTransformer.SassAndScss" />
                </translators>
            </css>
            <js>
                <minifiers>
                    <add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" />
                    <add name="MicrosoftAjaxJsMinifier" type="BundleTransformer.MicrosoftAjax.Minifiers.MicrosoftAjaxJsMinifier, BundleTransformer.MicrosoftAjax" />
                </minifiers>
                <translators>
                    <add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" />
                </translators>
            </js>
        </core>
    </bundleTransformer>
</configuration>
Coordinator
Jan 29, 2014 at 3:35 PM
In principle, everything is correct.

That is output instead of the contents of SCSS-file? Maybe there are some problems with authentication?
Jan 29, 2014 at 4:20 PM
I have created a brand new solution that shows this problem. You can download the code from https://www.dropbox.com/s/8yjx7btahl2jfz2/SassExperiment.7z. I've added a simple SCSS file to the page that turns text in a paragraph green. If you go to App_Start/BundleConfig.cs and change the value on line 14 from
BundleTable.EnableOptimizations = true;
to
BundleTable.EnableOptimizations = false;
you will see that the text no longer appears green.
Coordinator
Jan 29, 2014 at 6:14 PM
Visual Studio Development Server is running in the IIS classic mode, therefore you need to add the settings for the IIS classic mode, that described in the documentation:
<configuration>
    ...
    <system.web>
        ...
        <httpHandlers>
            ...
            <add path="*.sass" verb="GET"
                type="BundleTransformer.SassAndScss.HttpHandlers.SassAndScssAssetHandler, BundleTransformer.SassAndScss" />
            <add path="*.scss" verb="GET"
                type="BundleTransformer.SassAndScss.HttpHandlers.SassAndScssAssetHandler, BundleTransformer.SassAndScss" />
        </httpHandlers>
        ...
    </system.web>
    ...
</configuration>
Marked as answer by jdecock on 1/29/2014 at 2:58 PM
Jan 29, 2014 at 6:16 PM
I will give that a shot. I didn't realize that the built in server was using IIS classic mode. Thank you.
Coordinator
Jan 29, 2014 at 6:18 PM
In future I recommend you start to use the full version of IIS or at least the IIS Express.