Last Updated: February 25, 2016
· revgum

Tie a Build project to a Build Event

I'm really digging the YUI Compressor for .NET, it works like a charm and has some great short videos describing how to use it. I decided that I wanted to use a Post-Build event to run my compression, and I ran into a few hurdles along the way. The introduction video does a great job explaining how to use the MSBuild version from NuGet, but I think it was missing just a couple of details. Here's what I found;

YUICompressor didn't seem to like it when the compressed CSS / Javascript output file already exists. I didn't see an option to force over-writing the output files, so I set a Pre-Build Event to do this step for me.

del $(SolutionDir)UI\static\css\app.min.css
del $(SolutionDir)UI\static\js\app.min.js

I took the sample build project supplied by YUI Compressor and made my adjustments to the path and arguments for compression. Saving the file as .xml in my solution directory and setting the Post-Build event was a snap.

$(MSBuildBinPath)\msbuild.exe "$(SolutionDir)YUICompressor.xml"

Awesome. My css and javascript is compressed during my deployment process and I'm a step closer to integrating this into a continuous integration system should I feel the need..