6

I have a post-build event set up in Visual Studio 2010. The problem I am having is that the event doesn't run when I use Run (F5) to start debugging--it only seems to run if I explicitly Build (F6).

This seems to happen even when source files have changed (so it must build in order to run).

Is there a setting that controls this behavior?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Phil Sandler
  • 27,544
  • 21
  • 86
  • 147

5 Answers5

12

Postbuilds are only run after building. So when your build artifacts are up to date, it will not build and postbuilds will not run.

If it even won't run when it has to build, check the following:

In Visual Studio look at Tools -> Options -> Projects and Solutions -> Build an Run.

Is the option "Only build startup projects and dependencies on Run" checked?

Try to uncheck that option.

What is the value of the option "On Run, when projects are out of date"? It should be "Prompt to build" or "Always build" to be sure to trigger a build when pressing F5.

Jan
  • 15,802
  • 5
  • 35
  • 59
  • Setting "Always build" will not cause the post-build event to trigger after pressing F5. It will only happen, like the option's label clearly says, "when projects are out of date". – Allon Guralnek Dec 15 '10 at 20:34
  • Yes, you are right, but i just wanted to be sure thats its not on "Never build" – Jan Dec 15 '10 at 20:42
  • Hmm, the settings are already as you noted. From your answer, it seems you are saying that the post-build SHOULD fire when I hit F5 (assuming the project needs to build)? – Phil Sandler Dec 16 '10 at 14:38
  • Yes, when the project builds, the postbuild should run. The question is, builds the project when you hit F5? you should see a detailed log whats going on in the output window. – Jan Dec 16 '10 at 15:23
  • 1
    This worked for me. Although its a bit confusing why it works. – Wouter Schut Apr 12 '15 at 07:56
1

See Visual Studio: Run C++ project Post-Build Event even if project is up-to-date

Use Custom Build Step with a non existing file as output to always run your step.

Community
  • 1
  • 1
Stefan
  • 197
  • 1
  • 11
1

It only runs after a successful build. That why it's called a Post-Build Event.

Maybe what you're trying to accomplish can be done in a different way. Could you please give more details? What are you trying to do? What do you want to run before every debug session, and why?

Allon Guralnek
  • 15,813
  • 6
  • 60
  • 93
0

Check if the command is correct. A simple example would be:

copy "$(SolutionDir)$(ProjectName)\test.txt" ".\test.txt"
JJD
  • 50,076
  • 60
  • 203
  • 339
0

i've developed a simple VisualStudio AddIn, which intercepts the start command and does a rebuild of the solution, before it is actually starting the project.

Maybe it is useful for someone else: https://skydrive.live.com/redir.aspx?id=3dc36fae9ccfb71f&resid=3DC36FAE9CCFB71F!112&parid=root (BuildAndRunAddin.zip)

doerig
  • 1,857
  • 1
  • 18
  • 26