Sep
27
Posted under
Uncategorized We had to move from Visual studio team edition to Visual studio professional edition. When we installed the professional edition, the Microsoft test project that we had used for unit testing was not visible. So we started using NUnit for unit testing.
- We created a class library which had all the unit tests.
- Installed NUnit
- Right click the test library project, go to
Properties -> Debug.
Set Start external program to C:\Program Files\NUnit 2.4.1\bin\nunit.exe
- Set the test library as startup project.
- Run
The NUnit UI shows up. Run any one or group or all test cases. If there are any breakpoints in the code, the execution stops at breakpoint.
Sep
20
Posted under
Uncategorized All of .Net developers at one point or the other in their programming life stumble upon a need to create a Windows Service. One of the unintuitive factor about developing windows service is it can not be debugged like a winform or a webapp. The reason for this is, when you start it, only then does the service appear as a process in the ‘attach processes’ debugger window. So effectively you can not debug the OnStart event. Here’s a solution and it applies to .Net 2.0 web services and may not directly be useful for WCF services, or it might be.
I’ve also included steps from scratch that help in building a windows service.
- Create a ‘Window service’ project in Visual Studio, by default you will get a Service class which is inheritad from ServiceBase class. In the OnStart event handler of this class, add your code that the windows service is supposed to do on start. Handle OnEnd too if it’s necessary for your service’s purpose.
- Go to [Design] view of the Service class, the editor are will be gray, right click and ‘Add Installer’. When this is done, ‘ProjectInstaller.cs’ gets added to the project, which will have two components in the [Design] view - ServiceProcessInstaller adn ServiceInstaller. Go to properties of each of the component and make appropriate modifications such as Name of the service and Account (User/LocalSystem etc)
- Â Go to Project->Properties->Build Events and add the following to the ‘Post-build event command line’ section.
- installutil /u “$(TargetPath)” (add this only after the first time build+install) and on the next line,
- installutil /i “$(TargetPath)”
Make sure you’ve set the path for installutil.exe (Wherever the exe is on your machine, pick that path) in the environment variables of your computer.
- Go back to your main Service class that inherits from ServiceBase class, and in the ‘OnStart’ event handler add the following code, before the other code that follows.
#if DEBUG
if (!System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Debugger.Launch();
}
System.Diagnostics.Debugger.Break();
#endif
- Rebuild the project, and make sure there are no compilation or installation errors.
- Go to command prompt and type in “Services.msc”, in the Services window, right click on it and ’start’. At this point a debug dialog will popup.
-

- In the ‘Possible Debuggers’ section, select the Visual Studio IDE that you have your windows service project open, and click ‘Yes’.
- Boom!!! and you are now in the ‘OnStart’ event handler, debugging away merrily. Applause !!!
- Done.