I was wondering what the command would be using the dll referenced in a project for the following commandline:
"C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier\ajaxmin.exe" -JS -clobber ../Scripts/jquery-1.6.2.min.js ../Scripts/jquery-ui-1.8.16.min.js -o ../Scripts/Production/mvpApp.all.min.js
Sep 9, 2011 at 12:47 AM
Well, the first thing to consider is that the DLL does
absolutely no file access. It was implemented that way on purpose so we can quickly, easily, and (above all)
requirements on publishing assemblies with that security attribute, mostly involving lots of architecture, security, and code reviews with resident security experts and such. All the DLL does is work on in-memory strings.
So, if you have an application and you want to completely duplicate the command line above, your application will first need to read the two input files into a string, pass that string to the DLL using just the default code
settings, then write the returned minified string to the output file. Just to be clear,
if you are using the DLL, your application is completely responsible for reading and writing to the file system.
Reading the input files is pretty straight-forward -- just use standard C# System.IO classes like StreamReader and StringBuilder.
if you want to write your file to UTF-8 or UTF-16, then you don't need to do anything special and can just use standard C# output classes like StreamWriter. But if you have special characters and/or you want to write your output in ASCII or some other encoding format,
I'll write a larger article on how to use the fallback encoders soon, but the simple explanation is that you will need to create the appropriate Encoding object (System.Text namespace) with one of the two encoder fallbacks, and
use that encoding when you write your file. For instance, let's say you want to output this in the ASCII encoding. Create the ASCII encoding object like this:
var encoding = (Encoding)Encoding.ASCII.Clone();
encoding.EncoderFallback = new
And when you create your output stream, specify this encoding object in the constructor. For example, given the output path in the outputPath variable, and the minified code returned by AjaxMin in the minifiedCode variable:
outputStream = new
Hope that helps!