I'm trying to use OpenCover to get coverage metrics for a service using Topshelf. The application runs fine from the console.
When the application runs it prints the following:
The service is now running, press Control+C to exit.
Then once Control+C is pressed it prints
Control+C detected, attempting to stop service.
When done without OpenCover the application catches the Ctrl+C and stops normally, returning the command prompt when it's finished.
I'm running the application through OpenCover with the command:
OpenCover.Console.exe -target:service.exe -log:All -register:administrator
When done through OpenCover I think OpenCover catches the Ctrl+C immediately and then passes it to my service application. The result is that OpenCover dies immediately but the target application for coverage is still running and takes a few extra seconds to stop. I can see the service process still going in Process Explorer and it prints its cleanup messages to stdout as it dies.
If the application that OpenCover is trying to get metrics from shuts down after OpenCover has stopped can OpenCover still get coverage information?
OpenCover gathers information all the time from the target process however it does not export the information until the target process has stopped, it will also not export the information to file if it is stopped abnormally.
Your -register
option is invalid see usage guide.
Why not try a less intrusive way if stopping your service when in console mode - I usually just wait on an enter key.
If CTRL+C is something that top shelf imposes and can't be altered then wrap your app in your own service. It isn't that hard (there are wizards to help you) and will give you far more control.
There are plenty of articles to show how to make it run in both console and service modes.
OpenCover can sometimes work with a service again I refer you to the wiki and the -service
switch but this can be tricky to get working.