Post-Build Event on Run (F5) In Visual Studio?

2020-07-10 08:50发布

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?

5条回答
爷、活的狠高调
2楼-- · 2020-07-10 09:08

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-07-10 09:12

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?

查看更多
迷人小祖宗
4楼-- · 2020-07-10 09:16

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

copy "$(SolutionDir)$(ProjectName)\test.txt" ".\test.txt"
查看更多
甜甜的少女心
5楼-- · 2020-07-10 09:24

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.

查看更多
闹够了就滚
6楼-- · 2020-07-10 09:24

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)

查看更多
登录 后发表回答