When you install the Visual Studio 2012 RC release, and create a ASP.NET project, you might notice a dependency on an assembly called WebGrease. I've seen the question show up in comments on Scott Hanselman's blog post asking what it is, and I did intend to have this post out earlier this week, but as always free time is a premium.
What is WebGrease?
The features the initial version includes are:
- Creation of image sprites from images reference in CSS files.
- Auto-version naming of files.
Using WebGrease in your ASP.NET project
WebGrease is a dependency of the Web Optimization library in Visual Studio 2012 RC. So taking advantage of the new tools is very straight forward. Howard Dierking has a great post on Web Optimization changes in the RC, and I would suggest reading that post for understanding how to utilize the features in WebGrease that the Web Optimization library depends on.
Using the command line tool
In the lib folder of the package installation path, you will find WG.EXE. This utility will allow a developer to take advantage of the other features WebGrease offers, as well as the opportunity to be run at build time (or whenever) with a script.
Note: The current path is a bug, and the exe file will be moved to the tools folder in the next release.
If run on the command line with no parameters the wg.exe utility will display a set of help text, but really the syntax is simple:
wg.exe <operation switch> -in:<input file/folder> -out:<output file/folder>
The valid operation switches of WG.exe are:
Note: Only 1 operation switch can be used per execution of the wg.exe tool.
The in and out parameters can be file paths or folder. However if the input parameter is a folder, so should the output parameter, with the exception of when you want to execute the bundling operation
This is only the beginning!
There are a few command line parameters not covered in this post. The -c and -type parameters are related to using xml config files with WG.exe for specifying inputs and options. The config file schema and how to use it, requires a post of their own.
If you are using the features of Webgrease, either through the ASP.NET project functionality or the command line, I would really like to get your feedback!
PS: Before anyone points it out, I haven't optimized the scripts, images and css on this site yet with WG. I will soon :)