Script for building/debugging services

A

arthernan

I have found services debugging to be a big pain. One reason is because
the play button in VS is worthless for this kind of application.

So I wrote this scripts that will execute for an app whose name ends on
Service, it will lookup the debug directory, Stop the service copy the
executables and restart the service. Now there is a lot of room for
improvement. But I thought I'd share and maybe someone out there will
improve on it. It also executes when the app has just been built, so
you only need to attach to the process instead of hitting the arrow.

Or maybe I am missing something; and there is no need for this at all.

To make this work you need to open the Macro editor on the menu it is:
"Tools/Macros/Macro IDE ...". There you can edit the MyMacros template.

Public Module EnvironmentEvents

#Region "Automatically generated code, do not modify"

Private Sub BuildEvents_OnBuildDone(ByVal Scope As
EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles
BuildEvents.OnBuildDone
Debug.main()
End Sub

End Module



Public Module Debug
Private fullexepath As String = "C:\Program Files\My company\My
app"
Sub main()

Dim _project As EnvDTE.Project
_project = DTE.Solution.Projects.Item(1)

If
_project.Properties.Item("Title").Value.ToString.EndsWith("Service")
Then

Dim _process As Diagnostics.Process
_process =
Diagnostics.Process.Start("C:\Windows\system32\cmd.exe", "/c ""net stop
TNAEventService""")
_process.WaitForExit()



Dim OutputPath As String
OutputPath =
_project.Properties.Item("LocalPath").Value.ToString()
OutputPath +=
_project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value

For Each OutputPath In Directory.GetFiles(OutputPath)
Dim fi As FileInfo = New FileInfo(OutputPath)
Dim vFileStream As FileStream
If File.Exists(fullexepath + "\" + fi.Name) Then
If Not Directory.Exists(fullexepath + "\old") Then
Directory.CreateDirectory(fullexepath + "\old")
End If
File.Move(fullexepath + "\" + fi.Name, fullexepath
+ "\old\" + fi.Name + "." + Now.ToString("yyyymmdd hhmm"))
End If
File.Copy(OutputPath, fullexepath + "\" + fi.Name)
Next

_process =
Diagnostics.Process.Start("C:\Windows\system32\cmd.exe", "/c ""net
start TNAEventService""")
_process.WaitForExit()
End If
End Sub

End Module
 
A

arthernan

Has anybody had bad experiences debugging services?

I would love to hear an opinion to my post.

Arturo
 
D

David Levine

Why not run the service as a normal executable when you want to debug it?
You can pass it a command line argument (e.g. "exe") that tells it to run as
an executable - when there is no argument it runs itself as a service.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top