Less transformation error including .less files separately

Jul 16, 2014 at 10:29 AM
Hi thank you for your aweson work. I like this library.

I have one trouble

I have multi user site and one template. Each user have own color definition for this template. I need to create bundle for earch user and, add for earch user diferent color variables above init.less file

For one template init.less file exist

@import url("_css/base/css-reset.less");

@import url("_css/00_variables.less");
@import url("_css/02_base.less");
@import url("_css/03_components.less");
@import url("_css/04_header.less");
@import url("_css/05_content.less");
Examlpe of creating bundle
Bundle cssBundle = new Bundle(path);
cssBundle.Transforms.Add(new CssTransformer());
cssBundle.Transforms.Add(new CssMinify());
cssBundle.Builder = new NullBuilder();
cssBundle.Orderer = new NullOrderer();


When I try to run site, error occur

During translation of LESS-code, readed from the file '/content/themes/base/init.less', to CSS-code syntax error has occurred. 
See more details:

Error type: Name
Message: variable @color-4 is undefined
File: /content/themes/base/02_base.less
Line number: 17
Column number: 20
Source error:

Line 16:         margin-top: -1px;
Line 17:         background: @color-4;
Line 18:         content: "";
What I think, when transformation to css is precessing, transformer doesn't know about file 01_colors.less, because it is not in init.less file.

Is it any solution to solve this??

Thank you very much for your respond

Jul 16, 2014 at 1:32 PM
Edited Jul 16, 2014 at 1:32 PM
Hello, Paul!

Indeed the Bundle Transformer processes the assets separately. It is feature of the Bundle Transformer architecture and it will not change.

I recommend to you two ways of solving this problem:
  1. Register a assets with variables by using the @import directive and use custom VirtualPathProvider
  2. Create a custom item transformation
More about these solutions you can read in the «BundleTransformer.Less inject variables depending on context/request» discussion on the Stack Overflow.
Marked as answer by staro on 7/20/2014 at 10:14 PM
Jul 17, 2014 at 8:40 AM
Thank you VERY MUCH!!!

Your advise was very helpfull. It works.

Good work.

Many thanks