I am using the Microsoft Ajax Minifier to minify my javascript files. In the manifest, I would like to specify that all js files in a source folder should be minified into a different output folder. The original filename should be used as the output filename plus a variable should be appended. I would like to do something like the manifest below where the output uses a * wildcard and the variable is a version number of 4.60.
<?xml version="1.0" encoding="utf-8"?>
$(version) = "-4.60"
<root>
<output path="..\Scripts\Pages\*$(version)" type="js">
<input path="Scripts\PageSource\" type="js" />
</output>
</root>
Using a * in the output setting throws a build error but maybe there is a different wildcard character? There are a lot of output and input settings, which is why I'd like to specify a version number once and reuse it.
Could any of the settings in the targets file (see below) be used for this purpose? I could not find any examples that show what the ProjectDefaultSwitches and Configuration settings do.
<!-- 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"/>
</CreateItem>
<AjaxMinManifestTask ProjectDefaultSwitches="-define:$(DefineConstants))"
Configuration="$(Configuration)"
TreatWarningsAsErrors="false"
InputFolder="$(ProjectDir)"
OutputFolder="$(ProjectDir)Content\"
Manifests="@(AjaxMinManifests)" />
</Target>
Is this possible?
So far it appears that it is not possible to use wildcards and variables in the manifest files but I was able to accomplish my overall goal by using the second approach that @stijn suggested. Here is what I did:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="AjaxMinManifestTask" AssemblyFile="$(ProjectDir)Build\AjaxMinTask.dll" />
<Target Name="BuildAjaxMinManifests" AfterTargets="Build">
<Message Text="Processing Manifest" Importance="high" />
<CreateItem Include="@(None)" Condition="'%(Extension)'=='.ajaxmin'">
<Output TaskParameter="Include" ItemName="AjaxMinManifests"/>
</CreateItem>
<AjaxMinManifestTask ProjectDefaultSwitches="-define:$(DefineConstants)"
Configuration="$(Configuration)"
TreatWarningsAsErrors="false"
InputFolder="$(ProjectDir)"
OutputFolder="$(ProjectDir)"
Manifests="@(AjaxMinManifests)" />
<Message Text="Processing Pages" Importance="high" />
<PropertyGroup>
<VerNumber>4-62-0-0</VerNumber>
</PropertyGroup>
<ItemGroup>
<ToMinify Include="$(ProjectDir)Scripts\PageSource\*.js"/>
</ItemGroup>
<Exec Command="$(ProjectDir)Build\AjaxMin.exe %(ToMinify.Identity) -out $(ProjectDir)Scripts\Pages\%(ToMinify.FileName)-$(VerNumber).js -clobber" />
</Target>
</Project>
<Import Project="$(MSBuildProjectDirectory)\Build\AjaxMin.targets" />
TIP: It seems that changes to the AjaxMin.targets file are not recognized until the solution is reopened. I wasted an entire day going down rabbit holes until I figured this out.
The AjaxMinManifestTask portion of the AjaxMin.targets file kicks off a minification and consolidation of a number of js and css files according to a manifest. The format of the manifest XML is documented at the Microsoft Ajax Minifier website.
The Processing Pages portion of the AjaxMin.targets file kicks off a minification of every file in the Scripts\PageSource folder and outputs the result to the Scripts\Pages folder. It also appends the VerNumber value to the resulting filename.