I've been attempting to get minification and bundling working on my MVC3 project for some time, trying out quite a few different compressors and methods. I've finally settled on using Microsoft Ajax Minifier via an msbuild task in my project file. I'm only so far in to my configuration, but I've hit an immediate stumbling block; when I minify and combine my JS scripts in to a single file (using the task definition below), my combined file always contains two minified copies of each script.
I've cut out all other complicated msbuild tasks I've added, removed all but one JS script, and it's still happening. The below tags are the only part of my project file that I have manually modified:
<UsingTask TaskName="AjaxMin" AssemblyFile="$(MSBuildProjectDirectory)\..\_Build\AjaxMinTask.dll" />
<Target Name="AfterBuild">
<ItemGroup>
<JsFiles Include="**\res\js\libs\jquery.js" />
</ItemGroup>
<AjaxMin Switches="-global:jQuery,$" JsSourceFiles="@(JsFiles)" JsCombinedFileName="Combined.min.js" />
</Target>
Combined.min.js is created in the root of my web project (as expected), but it contains two minified copies of the jquery.js file.
I'm using Microsoft Visual Studio Ultimate 2012 RC (Version 11.0.50706.0 QRELRC July, 2012) and the references "AjaxMinTask.dll" file is the latest version (4.59.4576.13505) from here.
Now, here's the weirdest thing. Additionally, I have created completely new MVC3 projects in both VS 2010 and VS 2012, and copied & pasted the above lines in to their project files - only changing the path to AjaxMinTask.dll (to use the same as the broken project) and the path to the JQuery file (\scripts\jquery..js), and they work perfectly fine.
Unfortunately I can't paste the project file as it's too long for stack overflow, so I've zipped it up with the original jquery file I'm trying to minify / combine, the resulting "minified" file, and the AjaxMin assemblies I'm using:
[ Url Redacted ]
Alternatively, I'm very open to any other suggested methods that will allow me to minify / combine when I build in release mode in Visual Studio 2012, using .Net 4.0 and MVC 3.
Well, here's a weird gotcha... I've managed to fix this (after days of faffing about!) by either changing the "js" directory to another name ("javascript"):
<JsFiles Include="**\res\javascript\libs\jquery.js" />
or removing the "**\" from the beginning of the path:
<JsFiles Include="res\js\libs\jquery.js" />
I suspect this is a bug of some sort.