Panda
Panda

Reputation:

Can we execute a .bat file in post build event command line in visual studio?

Can we execute a .bat file in post build event command line in visual studio?

Upvotes: 72

Views: 98085

Answers (3)

Piotr Owsiak
Piotr Owsiak

Reputation: 6259

Sure, here's an example:

call "$(SolutionDir)scripts\copyifnewer.bat" "$(SolutionDir)libs\RLPL.Services.CertificateValidator.Basic.dll" "$(TargetDir)RLPL.Services.CertificateValidator.Basic.dll"
call "$(SolutionDir)scripts\copyifnewer.bat" "$(SolutionDir)libs\RLPL.Services.CertificateValidator.Common.dll" "$(TargetDir)RLPL.Services.CertificateValidator.Common.dll"

Just be aware of two possible issues you might have:

  1. the enclosing double quotes (see how each part is surrounded by " sign)

  2. if you want to call 2 or more batch files make sure you use call command otherwise you'll have a trouble finding why the second bat is not doing its job

Upvotes: 124

Polyfun
Polyfun

Reputation: 9639

As well as calling a .bat file, you can enter batch commands (i.e., the normal commands available from the Windows console--cmd.exe) directly into the Pre-build/Post-build fields. This may be preferable as it means you do not have to maintain the batch file separately, as all your commands will be part of the project.

Upvotes: 9

Mark Seemann
Mark Seemann

Reputation: 233347

Yes, by adding a call to it in the post-build event editor.

If you go to the Properties page for your project, you should select the Build Events tab. You can type in the call to your batch file in the Post-build event command line text box.

If you want to refer to the batch file using the paths included in the project or solution, you can click on the Edit Post-Build... button. This will open the Post-build Event Command Line dialog box.

This dialog box has a Macros >> button that you can click. It will show you all the available Macros that you can use to refer to folders and files within your solution.

When you select one of those macros, you can use the Insert button to insert them into your script.

Upvotes: 32

Related Questions