views:

10

answers:

1

I’m adding a post build task to run the Ajax Minifier (ajaxMin.exe) whenever a relase build of a project is conducted. I’ve added the code to the project to compress all CSS and JavaScript, but when triggering a build on the TFS build server I get lots of build errors in the BuildLog.txt with the message:

error : The Microsoft Ajax Minifier does not have permission to write to JS[filename].js

I get one message for each JavaScript and CSS file and rightly enough loking at the build output, no minification has taken place. The project is under source control, but I thought being a post build task, this wouldn’t matter as its minifying the output on the build server, not the source files themselves? The code added to my .csproj is as follows:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\AjaxMin.tasks" />
  <Target Name="AfterBuild" Condition=" '$(ConfigurationName)'=='Release' ">
    <ItemGroup>
      <JsFilesRelease Include="**\*.js" Exclude="**\*.min.js" />
      <CssFilesRelease Include="**\*.css" />
    </ItemGroup>
    <AjaxMin JsSourceFiles="@(JsFilesRelease)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".js"
         CssSourceFiles="@(CssFilesRelease)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".css"   />
  </Target>

Is there any way I can get around this restriction? I want to ensure that all outputted files from the above are minified and it seems its only the permissions that are preventing it.

Thanks

A: 

With your code, the Ajax minifier will minify any js and css files in the working directory your built takes place and its subfolders. You can debug by printing the working directory before your AjaxMin task :

<Message Text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)"/>

I think you should specify a more precise path to your output directory than "**". Are you working with VSS?

I do the same but with the Yui Compressor task (http://yuicompressor.codeplex.com/) instead of the MicrosoftAjax. You can find a study over the compressors here : http://coderjournal.com/2010/01/yahoo-yui-compressor-vs-microsoft-ajax-minifier-vs-google-closure-compiler/ I work with svn, CC.net and MSBuild.

Benjamin Baumann
Thats fine. Even though there should only ever be JS in the \js directory and css in the \stylesheets directory, if they do happen to be anywhere else, they'll get minified too. We are working with TFS for source control.
LDJ
What I meant is that your **\*.js would refer to your source files, that are probably locked with TFS. Your output files probably are in a _PublishedWebsite directory rather. Even if it is a post build task, the msbuild process is the very same that built your website, so it probably is started in the directory where is located your solution file. Do you run the build from Visual Studio? What is the value of MSBuildProjectDirectory ?
Benjamin Baumann