If you write a C# or VB.NET class library that contains ASP.NET controls that also have .js or .css files embedded in your assembly, you probably want to minify those files for optimal download size in production, but keep the files readable for coding and debugging. What if you could add a single <Import> to your class library’s project file that would automatically minify these files in Release builds, while leaving them untouched in debug builds?

Well, I wrote a .targets file and associated MSBuild task that uses Dean Edwards’ excellent Packer algorithm to make .js files really small. Just import the .targets file right after your last <Import> and you’re done.

You can get it here:

http://teamcity.dotnetopenauth.net:82/project.html?projectId=project3

Just click “Artifacts” then “Download all (.zip)” in the upper-right corner.

Or the source for it if you’re interested:

http://github.com/AArnott/JavascriptCssPackerTargets

Just click the “download” button to get it as a zip file.

Please take this as a tip and not an endorsement. This is not a Microsoft product—it’s just an open source project that I wanted to point out to you for you to evaluate whether it’s appropriate for your project. As far as the license goes, this MSBuild task uses code from Dean Edwards that is under the LGPL license, so the whole MSBuild task .dll ships under the LGPL license. While I don’t interpret that to mean that your shipping project must be under any particular license, you should consult your own attorneys and not take my word for it.

(cross-posted from http://blogs.msdn.com/vsproject/)

One thought on “Minify your EmbeddedResource .js and .css files in your MSBuild project”

Comments are closed.