简体   繁体   中英

VS2008 post-build event batch file

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?

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"

Just type it like this

d:\foo\bar\myMainScript.bat "$(MY_VSPROPS_MACRO_VAR_00)"

This worked for me. Dont use CALL function to call the batch file!!!.

Pass all the parameters into the main batch file and process things inside. If you have other batches or set of batches to be called, don't call them in the post build event, just call the other batch files from the main batch file.

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.

I think you might just need quotes around the path to the batch script, ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM