This project is read-only.

Using the Ajax Minifier Manifest Task

Microsoft Ajax Minifier supplies an AjaxMinTask.dll that contains a couple useful build tasks for your MSBuild projects.  One of the tasks is the AjaxManifestTask. The tool also supplies a simple targets file to simplify the addition of the functionality to your project: AjaxMin.targets. You can add a reference to that .targets file in your .csproj file like this:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\AjaxMin.targets" />

Note: the above <Import> element example is assuming that Microsoft Ajax Minifier has been installed on your system via the MSI install downloaded from this CodePlex site. If you are using the Nuget package with your project, copies of the DLL and TARGETS file will be under the tools folder of your package installation, so the $(MSBuildExtensionsPath) variable used in this <Import> example will not be what you want. You can encode the Project path using the Nuget installation path in your solution, but that path will change the next time you update the Nuget package because the package path contains the version number. The Nuget package is intended to be used by a project that wants to link to the AjaxMin.dll and utilize JavaScript and CSS minification functionality from within their application. If this is not what you want to do, if you are just trying to add minification of your JavaScript and CSS code at build time, the Nuget package is not the recommended path. Instead, install the application to your machine using the MSI, then add the AjaxMinTask.dll and AjaxMinTask.targets file to your solution. This will copy them into your project. Modify your .CSPROJ file to import the .TARGETS file from the path within your solution.

The contents of the targets file will look _something_ like this:

<Project xmlns="">
    <UsingTask TaskName="AjaxMinManifestTask" AssemblyFile="AjaxMinTask.dll" />

    <!-- target to build all ajaxmin manifest files in the project -->
    <Target Name="BuildAjaxMinManifests" AfterTargets="Build">
        <Message Text="Processing AjaxMin Manifests" Importance="high" />
        <CreateItem Include="@(None)" Condition="'%(Extension)'=='.ajaxmin'">
            <Output TaskParameter="Include" ItemName="AjaxMinManifests"/>

        <AjaxMinManifestTask ProjectDefaultSwitches="-define:$(DefineConstants))"
                             Manifests="@(AjaxMinManifests)" />

This .TARGETS file defines an MSBuild target that run after the project’s normal Build task. It looks for any files in your project with the extension “.ajaxmin” and assumes that the files are all AjaxMin manifest files. It then runs the AjaxMinManifestTask on each file.

  • Whatever the project has in its defines constants are passed to AjaxMin.
  • The configuration (Debug or Release) is passed.
  • Warnings are not treated as errors (you can edit this if you want to change that behavior)
  • The root of the project is the input folder; all <input> paths are relative to the project root.
  • The Content folder under the project root is the output folder; all <output> paths are relative to that folder.

Once this .targets file is added to your .csproj file, all you need to do to control your JavaScript and StyleSheet minification is create one or more XML files with the .ajaxmin extension,  add them to your project, set their Build Action property to “None,” and edit them to specify whatever arguments, output, input, resource, rename, norename, and symbolMap elements you wish.

Last edited Sep 23, 2013 at 8:53 PM by ronlo, version 5


E3RazPlan Dec 21, 2016 at 3:12 PM 
I would also like to know if variables, or maybe the -define:$(DefineConstants)) setting, can be used to specify a version number once that can be used on multiple output paths inside the manifest (.ajaxmin) file.

clopez2156 Feb 4, 2014 at 4:40 PM 

Are there any variables that could be used inside the manifest (.ajaxmin) files? something like $(version) ?

I'd like to achieve something like this:

<output path="bin\file.$(version).js" type="js">