MsBuild Task properties and discussion.

Aug 6, 2008 at 9:00 AM
Edited Aug 6, 2008 at 9:01 AM
Hi Folks,
   part of the .dll that is available to download includes an MsBuild task, which is a fraking good piece of functionality to use in any web project if you're using Web Deployment Projects to deploy your ASP.NET website. So ... how do you use it and what are the available properties?

Here's a snippet of code from an MsBuild file or your Web Deployment Project wdproj file (which is an msbuild file, if i'm not mistaken...)

    AssemblyFile="..\..\Projects\Yahoo.Yui.Compressor\Model\bin\Debug\Yahoo.Yui.Compressor.dll" />

<Target Name="MyTaskTarget">
        CssFiles/JavaScriptFiles data format: can be delimeted by a space, comma or semicolon. having an extra space after the delimeter is optional also.
           Valid examples:
               o) StylesheetSample1.css, StylesheetSample2.css
               o) StylesheetSample1.css,StylesheetSample2.css
               o) SampleJavaScript1.js;SampleJavaScript2.js
               o) SampleJavaScript1.js     SampleJavaScript2.js
        DeleteCssFiles: Yes | Yeah | Yep | True | FoSho | Fo Sho. Default is False. Anything else is False.
        CssCompressionType: YuiStockCompression | MichaelAshRegexEnhancements | HaveMyCakeAndEatIt or BestOfBothWorlds or Hybrid; Default is YuiStockCompression.
        DeleteJavaScriptFiles: refer to DeleteCssFiles, above.
        LoggingType: None | ALittleBit | HardcoreBringItOn;  Hardcore also lists javascript verbose warnings, if there are any (and there usually is :P ).
        CssFiles="StylesheetSample1.css, StylesheetSample2.css, StylesheetSample3.css"
        DeleteCssFiles="fo sho"
        LoggingType="ALittleBit" />


Ok, lets break this down.

This is the way you tell MsBuild that your using a 3rd party Task .. and that's the dll which will have all the Task magic in it. Pretty simple.
Traps for young players: making sure you get the correct path and file name right, for the AssemblyFile attribute.

This is the task that does the compression. You can allow it to do just Css compression or JavaScript compression or both. Lets check out what the each property does, including default settings.
CssFiles: Required property delimeted list of files. Valid delimeters are " ", ",", ";".
       Valid examples: 
               o) StylesheetSample1.css, StylesheetSample2.css
               o) StylesheetSample1.css,StylesheetSample2.css
DeleteCssFiles: Optional Property. Values: Yes | Yeah | Yep | True | FoSho | Fo Sho. Default is False. Anything else is set ignored and then defaulted to False.
CssOutputFile: Required Property. This is the file that will be created/overwritten with the all the compressed  css content.
CssCompressionType: Required Property. Values: YuiStockCompression | MichaelAshRegexEnhancements | HaveMyCakeAndEatIt or BestOfBothWorlds or Hybrid; Default is YuiStockCompression.
    This is the type of compression to use. YuiStockCompression is the normal port from the java YuiCompressor code. MichaelAshRegexEnhancements is a custom experimental port of the YuiStock compression. HaveMyCakeAndEatIt or BestOfBothWorlds or Hybrid is when the code does both YuiStock and MichaelAsh, and takes the smallest size result content.

JavaScriptFiles: Required Property. Refer to CssFiles, above, but for JavaScript instead.
DeleteJavaScriptFiles: Optional Property. Refer to DeleteCssFiles above, but for JavaScript instead.
JavaScriptOutputFile: Required Property. Refer to CssOutputFile above, but for JavaScript instead.

LoggingType: Required Property. Values: None | ALittleBit | HardcoreBringItOn. None means no output. ALittleBit is just that .. some nice summary stuff. I personally use this value. HardcoreBringItOn is verbose stuff .. especially when it comes to the JavaScript compression. The Yui code for JavaScript has the ability to dump out lots of suggestions to make your javascript better .. and setting this property will give you a plethora of warnings/suggestions.

Hope this helps

Jun 30, 2009 at 5:54 PM


First of all, thanks for this!

I'm trying to use it with a project I'm working on. I've copied the dlls over, and included the task and target in my project folder. I've changed the paths to represent proper files and locations within the project, I build my project... and nothing happens. The project just builds exactly as before, I don't even get any error messages! It's probably something I'm doing wrong as I've never had to mess around with build tasks before.

Am I missing a step, beyond putting the dlls somewhere, and referencing them (with a usingtask tag) and giving them settings (inside a target tag)? There are no errors logged in the 'output' window in visual studio, do errors get logged somewhere else?

thanks again

Jul 1, 2009 at 6:02 AM

Heya mate, thanks for giving this application a run.

Hmm, tough question. lets try a few questions...

1. You're building a web deployment project, right?
2. What is the Active Solution Configuration, in the Configuration Manager? A screenie would be lovely.
3. Can you also post up your web deployment prj file, please? if needs be, just snip out any sensitive data.

Cheers :)

Jul 2, 2009 at 11:11 AM
I think the problem was that we hadn't installed the web deployments project add-on for visual studio. It doens't sound like it will handle the 'aftermerge' event without it. It's not an issue any more as I've ended up using this in a different way (calling the javascript files via an aspx script which compresses and caches the javascript on the fly), because one of our developers is using a Linux equivalent of visual studio and wasn't sure he'd be able to run the build tasks from it. thanks for your help!
Jul 3, 2009 at 12:52 AM

pleasure mate :) That's one of the reason's i made sure the DLL was independant .. so u can use it any any custom scenario :) Not everyone uses Web Deployment projects. In fact, I wonder if many people do, actually :) Even less would use it with TFS + CI, I reakon.


I still got to do a simple .exe so it can be added to the standard Visual Studio Post Build event, if u want to use that instead :)