-
Notifications
You must be signed in to change notification settings - Fork 248
IIS Support
First let me say that I don't have the opportunity to write many ASP.NET applications at the moment nor do I have the need to gather coverage from a running ASP.NET application running under IIS. When I have the need to do such I have tended to use tools like IISExpress to host my code which is much easier to control in a CI environment. On other occasions I have resorted to self-hosting again because of the control that it affords one in a CI environment.
OpenCover is a profiler that uses the profiler API this is similar to such tools such as New Relic and AppDynamics and even developer tools like the awesome Ant profiler.
To get a profiler to load into IIS is the tricky bit because you need to define some environment variables that cause the profiler to load but if you get this wrong these profilers will load into every .NET process and could cause other issues.
However for those who really want to run against a full blown IIS then the following instructions (supplied by a user) will hopefully suffice.
The trick is to start OpenCover to run the w3wp.exe process in debug mode e.g.
OpenCover.Console.exe -target:C:\Windows\System32\inetsrv\w3wp.exe -targetargs:-debug -targetdir:C:\Inetpub\wwwwoot\MyWebApp\bin\ -filter:+[*]* -register:user
There are some prerequisites though:
- All applications running under the site must make use of the same app pool; you'll get errors in the EventLog otherwise.
- inetserver needs to be stopped, before starting w3wp.exe in debug mode. You can use the following command:
net stop w3svc /y
After testing/code coverage completion you can close the w3wp.exe process and start the inetserver again:
net start w3svc
This procedure was tested on a Win2008 machine with IIS7.5.
You can also run multiple OpenCover instances against separate IIS sites by using the –s option when running IIS to choose the siteid e.g.
OpenCover.Console.exe -target:C:\Windows\System32\inetsrv\w3wp.exe
-targetargs:"-debug -s 1"
-targetdir:%WebSite_Path%
-filter:+[*]*
-register:user
-output:%CoverageResult_Path%