Post build events using relative paths do not work in VS 2013

3.3k views Asked by At

I have a batch file two levels up.

..\..\PostBuildEventCopy.bat $(TargetDir) $(TargetName)

This batch file copies certain files to a location mentioned in the batch file. I get the below error. It seems to me that VS is not able to find the batch file.

Error: '..\..\PostBuildEventCopy.bat' is not recognized as an internal or external command, operable program or batch file. 

But when I mention the full path to the batch file, post build event goes through.

Am I missing something here? Any help appreciated.

2

There are 2 answers

1
Hans Passant On

Depending on the current directory with a relative path is never not a mistake. It is just not located where you hope it is, normally it is the build directory (bin\Debug or bin\Release). But that's a setting that can be changed so that will break your build event again.

Always specify full paths so avoid this kind of lossage. And always use "double quotes" around paths so spaces in the path name don't byte. Fix:

   "$(ProjectDir)\..\..\PostBuildEventCopy.bat" "$(TargetDir)" "$(TargetName)"

Click the Macros button in the Edit popup to see what ${Something} macros you can use.

2
Cadburry On

is not recognized as an internal or external command

Just means that it doesn't find your bat file. And i'm pretty sure that this is the problem! ;) - if you haven't changed your output directory from .\bin\debug or .\bin\release it means you have to store this file in your project directory. The two levels up gets resolved from the output directory!

Also be sure to add the start command before your bat-call.
My postbuild event for 2 levels up looks like this:

..\..\test.bat

and the test.bat is in the root of my project directory.