31

Part of the post build on my project is the execution of a program I wrote for testing the main application. Unfortunately, the post build process in visual studio locks up waiting for the executable to exit. So, i'm stuck closing my test program in order to have the post build process complete and my application run. How do I change this so VS does not wait for the program to return before launching? Thanks.

max
  • 1,020
  • 1
  • 15
  • 25

7 Answers7

28

I also found that the start trick didn't work and downloading a separate tool to complete such a simple task seemed excessive. After some additional searching I found this SO post which gave an answer that worked for my needs.

Just replace <actual-command-line-to-run> with your command. Remember to give the full path to the executable and encapsulate it in "quotes" if there's spaces in your path.

powershell start-process <actual-command-line-to-run>
Community
  • 1
  • 1
Grinn
  • 5,370
  • 38
  • 51
10

Wow, seems VS is really stubborn about this.

You can use this little tool that can launch apps without showing cmd windows (among other things). In your post build event:

c:\path\to\cmdow /run app.exe
javs
  • 798
  • 10
  • 28
  • 1
    This tool WILL run a post build script ASYNCHRONOUSLY! – Garfield Sep 26 '12 at 17:36
  • Sounds like this is the best solution so far, but requires using a separate tool. I'm looking for a batch command or C# code that would enable such fire & forget command launching from the post build event. – Filip Skakun Mar 07 '13 at 18:11
4

This seems to be a known issue of VS 2010 (e.g. here and here) and it seems it won't be fixed that soon.

Regarding a possible workaround, similar to the one mentioned by @RichieHindle, one of the MS Connect persons suggests:

START /WAIT cmd /c YourPostBuildTool.exe
superjos
  • 12,189
  • 6
  • 89
  • 134
  • I think this option is better than the powershell version because powershell should not be relied upon being present. Saying that, I guess these days powershell would facilitate cross platform support. – Tyeth Aug 01 '17 at 21:04
1

Running your test program via start might work. Change your post build step from this:

runtest.exe

to this:

start runtest.exe
RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • Doesn't work. It just opens the command line. Is the syntax wrong? start "$(ProjectDir)DDEClient\program.exe" original was "$(ProjectDir)DDEClient\program.exe" – max Aug 31 '09 at 10:00
  • Maybe `cmd /c start "$(ProjectDir)DDEClient\program.exe"` ? – RichieHindle Aug 31 '09 at 10:37
  • No luck either. I managed to get it to work by writing a autohotkey script that launchs my application using the Run command. Thanks for your help, though. It was appreciated. – max Aug 31 '09 at 10:57
  • @max: using `"$(TargetPath)"` with and without `start` or `cmd /c` didn't help. Can you please please share the script for running via Run command? – Robin Maben Mar 11 '11 at 12:08
0

I spent a considerable amount of time trying to figure this out. What you need to do is place "cmd" as the first line of your post-build event.

An example might look like this:

cmd
xcopy /Y $(ProjectDir)$(OutputDir)* C:\SomePath\*
David Torrey
  • 1,335
  • 3
  • 20
  • 43
0

If you utilize cruise control for your builds, you could place this in the publishers section which allows the build to finish before running the publisher tasks.

Additionally a custom msbuild task is quite trivial to build, if you know how to spin off a process in .net then it's really simple to do in msbuild. To do this you could edit your .csproj file or your .proj build script to use that custom task.

using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace MyTasks
{
public class SimpleTask : Task
{
    public override bool Execute()
    {
//something involving Process.Start
        return true;
    }
}
}

Then in your build script or csproj file you add the using for the task you created and call it.

Maslow
  • 18,464
  • 20
  • 106
  • 193
0

I uploaded a patch to MSBuild Extension Pack that implements a custom msbuild task called SmartExec that works around this issue.

http://msbuildextensionpack.codeplex.com/workitem/9053
http://msbuildextensionpack.codeplex.com/SourceControl/list/patches
Patch Id 9878

Rami A.
  • 10,302
  • 4
  • 44
  • 87