views:

65

answers:

2

I'm writing a post build event for visual studio project.

I have:

java -jar "$(ProjectDir)..\Tools\closure_compiler.jar"

but it turns out to be after compiled:

"D:\Projects\Source\Proj.Web\..\Tools\closure_compiler.jar"

which is an invalid directory, it just appends the dots. My problem is that I want to go back up 1 directory. The absolute file path is:

"D:\Projects\Source\Tools\closure_compiler.jar"

The full event is:

java -jar "$(ProjectDir)..\Tools\closure_compiler.jar" --js "$(ProjectDir)Scripts\*.debug.js" --js_output_file "$(ProjectDir)Scripts\script-bundle.min.js"

The error is:

Error   24  The command "java -jar "D:\Projects\Xormis\trunk\Source\Xormis.Web\..\Tools\closure_compiler.jar" --js "D:\Projects\Xormis\trunk\Source\Xormis.Web\Scripts\*.debug.js" --js_output_file "D:\Projects\Xormis\trunk\Source\Xormis.Web\Scripts\script-bundle.min.js"" exited with code 1.  Xormis.Web
A: 

The solution folder is typically one above the project directory, so give this a shot:

$(SolutionDir)\Tools\closure_compiler.jar

If that doesn't work, check out the full list of available macros. Maybe there's something else that'll come close.

Anna Lear
I dont see anything that came close. The file is 1 level up of the Solution Directory. Seems it doesn't support relative paths. Thanks for you help.
Shawn Mclean
Ah, my bad. I thought you meant 1 level up from the project dir. Sorry.
Anna Lear
A: 

Here's a possible workaround for this. You just need to convert the relative path to an absolute one. If visual studio can handle regular command prompt commands with command extensions, this may work:

set ProjectDir=$(ProjectDir)
java -jar "%ProjectDir:~0,-9%Tools\closure_compiler.jar"

pushd $(ProjectDir)
cd ..
set ClosureCompiler=%CD%\Tools\closure_compiler.jar
popd
java -jar "%ClosureCompiler%"

You may need to tweak these to fit your needs.

Jeff M
@Shawn: I'm not sure you saw my answer before you decided to delete. Although visual studio might not directly support relative paths as it seems it doesn't, there might be workarounds to your problem as I suggested in this answer. Please give it a try.
Jeff M
I deleted before I saw your answer, thanks, I'm going to try this.
Shawn Mclean