I am trying to do a poor man integration with xUnit.Net from inside Visual Studio as a post build event.
What I want is when I press Shift+F6 (Build the test project), after a successful build it should run xUnit.Console.exe and output the result in an html file and afterward launch the html file inside the browser.
Below is what I got so far and it work, but not to my liking (in that the browser will appear as a modal dialog of sort and I can't switch back and forward / toggle (using Alt-Tab) between Visual Studio and the browser. Right now I must close the browser for VS to gain focus again which kind of sucks.
My Post Build event below:
"$(SolutionDir)\Components\xUnit.net\xunit.console.exe" "$(TargetPath)" /html "$(TargetDir)result.htm"
"$(TargetDir)result.htm"
Any idea on how to get it so result.htm is displayed inside a browser and not in a modal mode?
After further test, it seems that any shell / command executed ran in modal mode. For example, I tried simple cmd.exe to pop up a Command shell.
I tried using start C:\Windows\IE7\iexplore.exe "$(TargetDir)result.htm" but that didn't work either...
This might be a bit round-about, but using Windows power-shell to start the process seems to work. I set the post build event to something like this:
powershell start-process <actual-command-line-to-run>
In this case, Visual Studio regains control immediately, without waiting for the started process to complete.
I was having some problems with the powershell method due to spaces in the path I was using, instead I decided to go with a vbscript post build event like this
Tests.vbs """$(DevEnvDir)mstest.exe"""
Then vbscript like this to launch the command async
'args
mstest = WScript.Arguments(0) 'mstest path
Set WshShell = WScript.CreateObject("WScript.Shell") 'Create Windows Shell Object
WshShell.Run "Tests.bat """ & mstest & """", 0, false 'Run Async
Set WshShell = Nothing
来源:https://stackoverflow.com/questions/1768358/how-to-create-an-asynchronous-build-event-in-visual-studio-2008