views:

41

answers:

3

I'm trying to execute a batch file to move a bunch of files around after a build so I've created a post-build event that looks like this:

$(ProjectDir)CopyPlugins.bat $(ConfigurationName)

The problem is that when Visual Studio tries to run the event I get the error that the process exited with code 9009

The problem appears to be that VS puts the entire line in quotes so that the command it runs is:

"C:\Users\kdmurray\Visual Studio 2008\Projects\Runner\Runner\CopyPlugins.bat Debug"

Of course what I intended it to do was a very subtle variation, changing the location of the closing quotation mark.

"C:\Users\kdmurray\Visual Studio 2008\Projects\Runner\Runner\CopyPlugins.bat" Debug

Is there any way around this rather annoying "help" that VS provides?

A: 

If you're trying to do complicated post-build copying it might be worth looking at the MSBuild Community Tasks project. It has a task that wraps RoboCopy.exe which might be a cleaner way to accomplish your task.

Generally I make a separate "build" project that is empty and does nothing but execute pre/post build steps. It works quite well.

Matt Olenik
I was hoping it wasn't going to come to that just to copy a couple of assemblies after a build.
kdmurray
A: 

I think you might just need quotes around the path to the batch script, i.e. your post-build event should be:

"$(ProjectDir)CopyPlugins.bat" $(ConfigurationName)

This worked for me for a C# project located in a directory with a space in its path.

Chris Schmich
Yea, tried that. Unfortunately it didn't work here. I end up with VS2008 trying to execute:`""C:\<path to batch>\CopyPlugins.bat" Debug"`Which just doesn't help anybody.
kdmurray
What project type are you working with? C#? C++?
Chris Schmich
C# -- but it's in a build event so I'm guessing it should be the same for most project types.
kdmurray
+2  A: 

Create two more batch files that just executes the first with different arguments.

CopyPlugins-debug.bat Call CopyPlugins.bat debug

CopyPlugins-release.bat Call CopyPlugins.bat release

And in VS post-build event "$(ProjectDir)CopyPlugins-$(ConfigurationName).bat"

Jesper Palm
That looks like the best we can do...It would be nice to have an IDE option to turn off the automatic quoting. We're developers, we're smart enough (usually) to figure out when we do and don't need it.
kdmurray