0

I have a project in "ASP.NET MVC 5" and use "less" for "bootstrap 3.1.1", and I use the following libraries for files less and min this:

http://www.nuget.org/packages/BundleTransformer.Core/ http://www.nuget.org/packages/BundleTransformer.Less/ http://www.nuget.org/packages/JavaScriptEngineSwitcher.Core/ http://www.nuget.org/packages/JavaScriptEngineSwitcher.Msie/ http://www.nuget.org/packages/MsieJavaScriptEngine/

and I have de similar proyect in MVC 4, but in MVC 5 when I set BundleTable.EnableOptimizations in true like this:

public static void RegisterBundles(BundleCollection bundles)
{
    BundleTable.EnableOptimizations = true;

the following error occurs, does not interpret files "less" with variables, for example the error is:

Error type: Name
Message: variable @font-family-base is undefined
File: /Content/bootstrap/scaffolding.less
Line number: 29
Column number: 15
Source error:

Line 28: body {
Line 29:   font-family: @font-family-base;
-----------------------^
Line 30:   font-size: @font-size-base;

but if I include/import the file with vars in /Content/bootstrap/scaffolding.less:

@import "variables.less";
@import "mixins.less";

the error doesn't happen, and the error proceeds to the next file.

Edit

Now the same thing happens to me but with ASP.NET MVC 4, these are the libraries that I have installed by nuget. I don't understand what the problem is or if something happens with compatibly:

<package id="AjaxMin" version="5.6.5100.19204" targetFramework="net40" />
<package id="AngularJS.Core" version="1.2.16" targetFramework="net40" />
<package id="Antlr" version="3.5.0.2" targetFramework="net40" />
<package id="BundleTransformer.Core" version="1.8.17" targetFramework="net40" />
<package id="BundleTransformer.Less" version="1.8.14" targetFramework="net40" />
<package id="BundleTransformer.MicrosoftAjax" version="1.8.15" targetFramework="net40" />
<package id="FontAwesome" version="4.1.0" targetFramework="net40" />
<package id="JavaScriptEngineSwitcher.Core" version="0.9.5" targetFramework="net40" />
<package id="JavaScriptEngineSwitcher.Msie" version="0.9.5" targetFramework="net40" />
<package id="jQuery" version="1.10.2" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi" version="4.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net40" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net40" />
<package id="Microsoft.Owin" version="2.1.0" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="Modernizr" version="2.7.2" targetFramework="net40" />
<package id="MsieJavaScriptEngine" version="1.1.3" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net40" />
<package id="Owin" version="1.0" targetFramework="net40" />
<package id="Twitter.Bootstrap.Less" version="3.1.1" targetFramework="net40" />
<package id="WebActivatorEx" version="2.0" targetFramework="net40" />
<package id="WebGrease" version="1.5.2" targetFramework="net40" />

web.config:

<sectionGroup name="bundleTransformer">
    <section name="core" type="BundleTransformer.Core.Configuration.CoreSettings, BundleTransformer.Core" />
    <section name="less" type="BundleTransformer.Less.Configuration.LessSettings, BundleTransformer.Less" />
  <section name="microsoftAjax" type="BundleTransformer.MicrosoftAjax.Configuration.MicrosoftAjaxSettings, BundleTransformer.MicrosoftAjax" />
</sectionGroup>
<sectionGroup name="jsEngineSwitcher">
    <section name="core" type="JavaScriptEngineSwitcher.Core.Configuration.CoreConfiguration, JavaScriptEngineSwitcher.Core" />
</sectionGroup>

...

<handlers>
  <add name="LessAssetHandler" path="*.less" verb="GET" type="BundleTransformer.Less.HttpHandlers.LessAssetHandler, BundleTransformer.Less" resourceType="File" preCondition="" />


...

<bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd">
  <core>
    <css defaultMinifier="MicrosoftAjaxCssMinifier">
      <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="LessTranslator" type="BundleTransformer.Less.Translators.LessTranslator, BundleTransformer.Less" />
      </translators>
    </css>
    <js defaultMinifier="MicrosoftAjaxJsMinifier">
      <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>
  <less useNativeMinification="false" ieCompat="true" strictMath="false" strictUnits="false" dumpLineNumbers="None">
    <jsEngine name="MsieJsEngine" />
  </less>
</bundleTransformer>
<jsEngineSwitcher xmlns="http://tempuri.org/JavaScriptEngineSwitcher.Configuration.xsd">
  <core>
    <engines>
      <add name="V8JsEngine" type="JavaScriptEngineSwitcher.V8.V8JsEngine, JavaScriptEngineSwitcher.V8" />
      <add name="MsieJsEngine" type="JavaScriptEngineSwitcher.Msie.MsieJsEngine, JavaScriptEngineSwitcher.Msie" />
    </engines>
  </core>
</jsEngineSwitcher>

Edit 05-24-14

BundleConfig.cs part of Css config:

CssTransformer cssTransformer = new CssTransformer();
NullOrderer nullOrderer = new NullOrderer();

Bundle cssBundle = new CustomStyleBundle(BundleName.Css);
cssBundle.Include("~/Content/bootstrap/bootstrap.less");
cssBundle.Include("~/Content/font-awesome.css");
cssBundle.Include("~/Content/site.less");
cssBundle.Transforms.Add(cssTransformer);
cssBundle.Orderer = nullOrderer;
bundles.Add(cssBundle);
andres descalzo
  • 14,887
  • 13
  • 64
  • 115

1 Answers1

3

The problem is this, in BundleConfig.cs the following configuration does not resolve less files correctly. maybe they need to add some additional property, but it does not work.

this is the problem, if this option removes the less files are processed correctly.

//CssTransformer cssTransformer = new CssTransformer();
NullOrderer nullOrderer = new NullOrderer();

Bundle cssBundle = new CustomStyleBundle(BundleName.Css);
cssBundle.Include("~/Content/bootstrap/bootstrap.less");
cssBundle.Include("~/Content/font-awesome.css");
cssBundle.Include("~/Content/site.less");
//cssBundle.Transforms.Add(cssTransformer);
cssBundle.Orderer = nullOrderer;
bundles.Add(cssBundle);

I not know what the right settings for "Transforms", but removing it solved my problem and the file is generated correctly and min.

andres descalzo
  • 14,887
  • 13
  • 64
  • 115
  • I wish I had seen this question 8 hours ago... I have tried so many things... and finally it's this simple. Anyway, I'm glad you posted the answer - thanks – Martin Hansen Lennox Jun 01 '15 at 20:51
  • 1
    This is because the `CustomStyleBundle` class already contains an instance of the `CssTransformer` or `StyleTransformer` class. In your case, transformations from the `CssTransformer` or `StyleTransformer` class apply twice, which leads to errors. All of these points are described in the [“Examples of usage”](https://bundletransformer.codeplex.com/wikipage?title=Examples%20of%20usage) section of documentation. – Andrey Taritsyn Dec 09 '15 at 10:02
  • @AndreyTaritsyn Thanks for the comment. It is useful for me – andres descalzo Dec 09 '15 at 12:04