Shawn Mclean
Shawn Mclean

Reputation: 57479

Relative paths in visual studio command-line file directory

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

Upvotes: 1

Views: 3440

Answers (2)

Jeff Mercado
Jeff Mercado

Reputation: 134571

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.

Upvotes: 2

Adam Lear
Adam Lear

Reputation: 38778

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.

Upvotes: 0

Related Questions