Wednesday, March 17, 2010

Style sheet compression and .less add-in...updated with source

6/2/2010 Update - Project enhanced and now on codeplex!

Design time minification and .net less for style sheets.
Read my previous post on this subject.  

Known Issues
It has been reported that this does not work in 'web site project'.  I do not  use those anymore, not since they brought back our 'web application project'.  If anyone wants to try and make it work, the code is attached.

Source Code
I finally got around to updating this to the latest version of the less engine and api.   In addition, I had been promising source code for a while now.

Click to download

Shout it
kick it on


Unknown said...

Thanks for updating this Wayne, great work. Just a quick question though - am I correct that :nth-child(n) gets filtered out?

:nth-child(odd) and :nth-child(even) seem to work perfectly, but when I put a number in there the LESS compiler seems to filter everything out...?

Hope you can help me out. Thanks!

Wayne Brantley said...

unsure - ask that in the .less google group.

Anonymous said...


Thanks for this. works great.

P.S. Could you change your blog to include the date a post/comment was made? just displaying the time against a post/comment is not very helpful

Wayne Brantley said...


Kamran A said...

Would you be able to post this add-in on CodePlex? That way maybe some of us can jump on the bandwagon and add patches. :)

I use the Publish feature in VS 2010 because of web.config transforms and File System publishing. I'm worried that the .less files will be published too... obviously don't want that; just want the generated CSS files.

No idea how to patch it to do that, but at least a CodePlex project would have SVN and track source code changes/issues.

Matt said...

Wayne, great update! Do you have plans to support VS 2010?

Eli Gassert said...

I made a tweak to TransformLessToCss that allows for @imports to work properly. I have all my custom variables and functions in one less file and import it into my other less files. This wasn't working in the current addin, so I made a quick tweak to fix it by setting the CurrentWorkingDirectory to the directory of the current LESS file... seems to work like a charm. Also, By changing the addin's version to 10.0 VS2010 can use it no problem. Here's the code:

private string TransformLessToCss(string fullFileName)
var config = new dotless.Core.configuration.DotlessConfiguration { MinifyOutput = true };

// Transform file content from less to css
ILessEngine less = new EngineFactory().GetEngine(config);
LessSourceObject lso=new LessSourceObject();
lso.Key = fullFileName;
using (StreamReader rdr = File.OpenText(fullFileName))

var current = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(new FileInfo(fullFileName).DirectoryName);

var ret = less.TransformToCss(lso);


return ret;
//return less.TransformToCss(fullFileName);