ajax minifier with VS 2008

Apr 28, 2011 at 5:25 AM

Is it possible to use latest version with VS 2008 ( framework 3.5 ) ? 

If not, what is the latest build that will work ?  Is there anything I can do it make it work with 2008 ?

When I got latest... I now get this error when I build...

error MSB4062: The "AjaxMin" task could not be loaded from the assembly C:\Program Files (x86)\MSBuild\Microsoft\MicrosoftAjax\ajaxmintask.dll. Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\Microsoft\MicrosoftAjax\ajaxmintask.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. Confirm that the <UsingTask> declaration is correct, and that the assembly and all its dependencies are available.

Thank you


Apr 28, 2011 at 11:50 PM

Hmmm. The AjaxMinTask looks like it's being built to .NET Framework 4. I'll check with Eugene to see if we can bump that down to 2.0.

Apr 29, 2011 at 3:11 PM

That would be great.

In the mean time, I've come up with a .BAT file which can be executed as a post build process, which will call ajaxmin.exe on all your .js and .css. I'll post it here in case anyone else is having the same problem as myself...



@echo off

rem -------------------------------------------------------------
rem A somewhat fancy .BAT file.
rem It will run ajaxmin.exe on all our .JS and .CSS files, to produce .MIN.JS  and  .MIN.CSS files.
rem -------------------------------------------------------------

set source_path=.
set include=scripts\*.js css\*.css
setlocal enableextensions enabledelayedexpansion

rem -------------------------------------------------------------
rem First, recursively find all files which end with .JS or .CSS ( but excluding any .min.js  or .min.css files )
rem -------------------------------------------------------------

FOR /r %source_path% %%G IN (%include%) DO (

    ECHO %%G|findstr /i ".min." >nul:
    if ERRORLEVEL 1 (
        rem -------------------------------------------------------------
        rem Set file1 = FULL PATH of source file
        rem Set file2 = FULL PATH of output file ( with '.min.' appended near end )
        rem -------------------------------------------------------------
        set file1=%%~dpnG%%~xG
        set file2=%%~dpnG.min%%~xG
        rem -------------------------------------------------------------
        rem Get the NEWER of the source & output files.
        rem We only want to run ajaxmin if the SOURCE is newer than the OUTPUT ( we do this by running a sorted DIR command with our 2 files )
        rem -------------------------------------------------------------
        FOR /F "Skip=1 Delims=" %%I In ('dir /b /OD !file1! !file2!') Do Set _Newer=%%I
        rem -------------------------------------------------------------
        rem Is the newer of the 2 a '.min.' file ? If so, we don't need to process this file.
        rem Otherwise, the SOURCE is newer than our current .min. file... so run ajaxMin.exe on the SOURCE to produce a new OUTPUT.min file
        rem -------------------------------------------------------------
        ECHO !_Newer!|findstr /i ".min." >nul:
        if ERRORLEVEL 1 ( ajaxmin.exe -clobber:true !file1! -out !file2! )


May 4, 2011 at 6:34 PM

With version 4.19, I bumped the required .NET version down to 3.5. This means it should work with VS2008 now.

Apr 21, 2012 at 6:56 PM

Hi, I build a better and simple batch file; that compress *.js|*.css.

*just copy and paste this:

:: Download ajaxmin to exec. http://ajaxmin.codeplex.com/
:: This file should be save as encoding UTF-8 (to accept )
:: just compact *.js|*.css
:: . = current dir
:: -clobber = overwrite file
:: /r = recursive
:: ~d = drive letter only
:: ~p = path only
:: ~n = file name only
:: ~x = file extension only
:: ~dpn = full path without extension
PATH=%PATH%;c:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier
SET include=*.js *.css
SET root_path=.
SETLOCAL enableextensions enabledelayedexpansion
FOR /r %root_path% %%F IN (%include%) DO (
ECHO %%F|findstr /i ".min"%%~xF >nul:
ajaxmin -clobber "%%F" -o "%%~dpnF.min%%~xF"