1

I'm trying to run a pre-build event which passes all the JavaScript files in a directory to MS's Ajax Minifier. Unfortunately, this tool excepts file names as individual arguments (it cannot parse "*.js"). I have quite a few JavaScript files and I really don't want to list them individually in the pre-build event window.

This is my current pre-build command:

"$(SolutionDir)Tools\AjaxMin.exe" "$(ProjectDir)*.js" -out  "$(ProjectDir)Generated\Generated.js" -clobber

Does anyone know the proper syntax (or if there even is one) to make this do what you'd expect it to do?

Thanks for any assistance.

MgSam
  • 12,139
  • 19
  • 64
  • 95

1 Answers1

1

Prebuild event is passed to shell that is why you can set a cmd-script like below as a pre-build event:

::Force variables to be evaluated at execution time
SETLOCAL ENABLEDELAYEDEXPANSION

SET parameter=
SET proj=$(ProjectDir)*.js

::Concatenate all the file names (surrounded by quotes) into a single string
FOR %%F IN ("%proj%") DO (SET parameter=!parameter! "%%F")

::Execute command
"$(SolutionDir)Tools\AjaxMin.exe" %parameter% -out  "$(ProjectDir)Generated\Generated.js" -clobber

Here we are accumulating all js filenames in parameter variable and passing it to ajaxmin.exe.

MgSam
  • 12,139
  • 19
  • 64
  • 95
Raman Zhylich
  • 3,537
  • 25
  • 23
  • Just copy/paste this into pre-build event command-line property of your project in Visual Studio – Raman Zhylich Jul 13 '12 at 21:35
  • 1
    Thanks for your help. I fixed a syntax mistake in your answer and reformatted it with some newlines and comments so its crystal clear what's going on for anyone else who might benefit from this. If only VS would let you write Powershell scripts in pre/post-build... – MgSam Jul 16 '12 at 13:46