MSBuild Task Tweaks

Mar 6, 2009 at 8:13 PM
First of all, thank you for your code and effort.  I plan on using your tasks in my codeplex project soon (will send you link when I do).

Couple things that could use improvement in your msbuild task. 
  • Do not require ThreadCulture.  I didn't supply it and it generated the generic error of failed to read data
  • Display real error in console instead of generic error
  • This is the most important of three.  Please support spaces in the file paths.  I think this is the cause of many peoples bugs.  The best way to do this is to not accept a string for JavascriptFiles and CssFiles, but instead use normal MSBuild construct of TaskItem[].

Here are the relevant code changes

public CompressorTask()
    JavaScriptFiles = new ITaskItem[0];
    CssFiles = new ITaskItem[0];

public ITaskItem[] CssFiles { get; set; }
public ITaskItem[] JavaScriptFiles { get; set; }


//fileList = CompressorTask.ParseFiles(this.CssFiles);
fileList = this.CssFiles.Select(f => f.ItemSpec).ToList();


//fileList = CompressorTask.ParseFiles(this.JavaScriptFiles);
fileList = this.JavaScriptFiles.Select(f => f.ItemSpec).ToList();


// Check to make sure we have the bare minimum arguments supplied to the task.
if (this.CssFiles.Length == 0 &&
 this.JavaScriptFiles.Length == 0)


Mar 6, 2009 at 9:11 PM
Hi Jhenning,

thanks heaps for the post.

1) ThreadCulture is required? I swore i made that optional! I'll double check .. but it should NOT be required. By default i wanted to make it en-gb (i think i have it coded, too). I'll double check.
2) real error. hmm. i'll see if i can print out the inner exception, assuming it's been bubbled through. no promises, though.
3) ITaskItem ?? WIKID! i never knew about that. I'll definately change the code as suggested with your patch, above. I'll try and do this over the weekend and the check in the code (maybe make another build).

cheers jhenning!
Mar 24, 2009 at 12:21 AM

i've added your ITaskItem suggestion to the code. I'm not sure how to test it OR to correctly set the msbuild task CSSFiles or JavaScriptFiles property in the .xml file, to work with an ITaskItem type.

Currently i have

CssFiles="StylesheetSample1.css, StylesheetSample2.css, StylesheetSample3.css, StylesheetSample4.css"

and it thinks that is one file, not 4.
Mar 24, 2009 at 3:31 AM
Nevermind dude - i've got it working perfectly now :) code to be uploaded in a tick.

thanks again! love it :)