I frankly got tired of all the steps required to test a new build of a Windows service so I developed a technique I have not seen before where you can automate the steps.

Here is what to do:

1) In the ‘Post-Build’ event, add the following commands:

installutil /u “$(TargetDir)YOURSERVICENAME.exe”
installutil “$(TargetDir)YOURSERVICENAME.exe”

this assumes you have added installutil to your path and that you have manually installed the service (as the first thing it does is uninstall and reinstall).

2) Using the MSBUILD events in the Macro IDE do the following:

a) Open the Macro IDE and select the EnvironmentEvents from the Macro IDE.
b) Add code to the event BuildEvents_OnBuildProjConfigDone

This is what the code should look like:

36 Private Sub BuildEvents_OnBuildProjConfigDone(ByVal Project As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String, ByVal Success As Boolean) Handles BuildEvents.OnBuildProjConfigDone
37
38 If Project.Contains(“YOURNAMEOFPROJECT”) Then
39
40 If Success Then
41
42 Try
43 Dim oAlerts As ServiceController = New ServiceController(“YOURSERVICENAME”)
44
45 oAlerts.Start()
46
47 System.Threading.Thread.Sleep(10000)
48
49 Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
50 Dim trans As EnvDTE80.Transport = dbg2.Transports.Item(“Default”)
51 Dim dbgeng(1) As EnvDTE80.Engine
52
53 dbgeng(0) = trans.Engines.Item(“Managed”)
54 Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, “YOURCOMPUTERNAME”).Item(“YOURPROCESSNAME.EXE”)
55 proc2.Attach2(dbgeng)
56 Catch ex As System.Exception
57 MsgBox(ex.Message)
58 End Try
59
60
61 End If
62 End If
63
64 End Sub

So now I can simply launch Visual Studio 2005 and these events will do all the work and stop on a breakpoint (please note you will get messages warning you cannot run a service from Visual Stuido. You can ignore these in my experience). Also a debugger tends to pop-up at the end. However in spite of these small items, this saves a lot of time.

Thanks,
Damon

Post a Comment