Basically, my end goal is to remove already present .min.js and CSS files when building my Visual Studio solution while I have Ajax Minifier (version 4.20) as one of MSBuild task which minifies .js and .css files.
According to Ajax Minifier documentation, I could use the -clobber
option to achieve the above mentioned goal. However, I'm not able to figure out where in Visual Studio MSBuild project task I can use this option. I'm successfully able to use the -clobber
option from Ajax Minifier command-line tool though.
Here is the configuration code which I have in my project (.csproj) file...
<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" />
<Target Name="AfterBuild">
<ItemGroup>
<JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" />
</ItemGroup>
<ItemGroup>
<CSS Include="**\*.css" Exclude="**\*.min.css" />
</ItemGroup>
<AjaxMin JsSourceFiles="@(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".min.js" CssSourceFile开发者_JS百科s="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" clobber="true" />
</Target>
However, when I compiled my solution, I got following error - not sure why?
The "clobber" parameter is not supported by the "AjaxMin" task. Verify the parameter exists on the task, and it is a settable public instance property.
From what I can tell from the docs, it looks like the clobber switch isn't available. The fact that its not available seems to indicate that deleting out of date files would be handled by the task. Having the task take care of file management makes a quite a bit of sense to me. That being said, are you sure you need the clobber switch?
If you do, you can either call the console version of AjaxMin by using the exec task:
<Exec Command="C:\PathToAjaxMin\AjaxMin.exe _options_here_" />
Exec Task
C:\"Program Files (x86)"\MicroSoft\"MicroSoft Ajax Minifier"\AjaxMin.exe -css $(ProjectDir)css\style1.css $(ProjectDir)css\style2.css $(ProjectDir)css\style3.css -o $(ProjectDir)css\master.min.css -clobber:true
Note: make sure the command is in one line in the POSTBuild Event
This is what I am using. If you are combining script, change the -css to -js.
Based on the document: http://ajaxmin.codeplex.com/wikipage?title=Command-Line%20Switches
By default, -clobber is set as false. so needs to specify true at the end if you want to replace existing output file.
You don't need the -clobber switch for the build task, which uses AjaxMin.DLL. That switch is only needed for AjaxMin.EXE.
You just need to pass in the -clobber
switch correctly.
Change
<AjaxMin JsSourceFiles="@(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".min.js"
CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css"
clobber="true" />
to
<AjaxMin JsSourceFiles="@(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".min.js"
CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css"
Switches="-clobber" />
精彩评论