Automatically stop / restart the ASP.NET development server on the assembly

Is there a way to automatically stop the ASP.NET development server (Cassini) whenever I build / rebuild in VS2008 (and then obviously start again when necessary)? Maybe somewhere there is a hidden configuration setting? Or at least some way to do this as an event after the build?

For some background, the problem is that I am using Spring.NET for dependency injection, etc., but it loads its singletones into Application Start, which means that if I change any related spring code / configuration, I have to stop the development server so that it starts the next debugger / start again, ensuring that the application start event is fired again. In other words, even if you change a bunch of code / config and then start debugging again, it actually does not start again, since it is already running, so your new code is not used.

+32
visual-studio cassini
May 20 '09 at 7:58 a.m.
source share
6 answers

So, I got a workaround based on Magnus answer, but using the following relatively simple macro (why do they force you to use VB for macros? I feel that everything is dirty):

Imports System Imports System.Diagnostics Public Module KillCassini Sub RestartDebug() If (DTE.Debugger.DebuggedProcesses.Count > 0) Then DTE.Debugger.Stop(True) End If KillCassini() DTE.Debugger.Go(False) End Sub Sub KillCassini() Dim name As String = "WebDev.WebServer" Dim proc As Process For Each proc In Process.GetProcesses If (proc.ProcessName.StartsWith(name)) Then proc.Kill() End If Next End Sub End Module 

Basically, if the debugger is currently running, it will stop it and then kill all processes named "WebDev.WebServer", which should be all instances of Cassini, and then start the debugger again (which implicitly starts Cassini). I use proc.Kill() because neither proc.CloseMainWindow() nor proc.WaitForExit(1000) work ...

In any case, as soon as you receive your macro, you can assign its keyboard shortcuts or create your own buttons on the toolbar to launch it.

+9
May 21 '09 at 4:05
source share

Workaround: Debugging Global.aspx.cs Application_Start () with ASP.Net Web Server in Visual Studio

The inclusion of "Edit and Continue" in the web server project worked for me. It disables cassini when you stop debugging, but reloads cassini when you start debugging.

+22
Jan 19 '10 at 22:52
source share

I just open the command line (runas admin)

do the following. He must kill all of them.

 Taskkill /IM WebDev.WebServer40.EXE /F 
+8
Apr 26 '13 at 6:28
source share

The only way I know is to create a custom Cassini start in the post.build event. This custom-made process kills all instances of Cassini and launches a new one. For this to work, you will need to create a small command line utility. I called it SpawnProcess here.

 using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Diagnostics; namespace SpawnProc { class Program { public static void Main(string[] args) { if (args.Length > 0) { // Kill all current instances FileInfo fi = new FileInfo(args[0]); string name = Path.GetFileNameWithoutExtension(fi.FullName); foreach (Process proc in Process.GetProcessesByName(name)) { proc.Kill(); } ProcessStartInfo startInfo = new ProcessStartInfo(args[0]); if (args.Length > 1) { startInfo.Arguments += "/port:" + args[1]; } if (args.Length > 2) { startInfo.Arguments += " /path:\"" + args[2].Trim(new char[]{'"'}) + "\""; } if (args.Length > 3) { startInfo.Arguments += " /vpath:\"" + args[3].Trim(new char[]{'"'}) + "\""; } try { Process.Start(startInfo); } catch (Exception ex) { Debug.WriteLine("Error: " + ex.Message); for (int i = 0; i < args.Length; i++) { Debug.WriteLine("args[" + i + "]: " + args[i].ToString()); } } } } } } 

Then you should instruct Visual Studio not to use Cassini. Get properties for your web application -> Web and select "Use a custom web server", enter something like: http://localhost:1685/ (or any port number that you would like to use). Then enter this command in the event after the build:

 "$(ProjectDir)..\SpawnProc\bin\debug\SpawnProc" "C:\Program Files (x86)\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.exe" 1685 "$(ProjectDir)" / 

Make sure your paths are correct, for example, since I am running a 64-bit OS, my path to the program files is different from the 32-bit OS. In addition, my SpawnProc.exe is located in a subproject.

+7
May 20, '09 at 13:19
source share

Inspired by this post and another about cleaning up the code, I added a macro as a PostDebug event. Therefore, every time the debugger returns, it deletes all WebDev.WebServer-s. (And I relaxed the restriction of ProcessName.)

Note. This will probably lead to the removal of all WebServers, as well as WebServers of other debugging sessions (which I can do, at the moment I usually don’t). So you can only search for child processes or something like that (and post this code here ;-)).

So my code looks like this:

 Private Sub DebuggerEvents_OnEnterDesignMode(ByVal Reason As EnvDTE.dbgEventReason) _ Handles DebuggerEvents.OnEnterDesignMode If (Reason = dbgEventReason.dbgEventReasonStopDebugging) Then Dim name As String = "WebDev.WebServer" Dim proc As System.Diagnostics.Process For Each proc In System.Diagnostics.Process.GetProcesses() If (proc.ProcessName.StartsWith(name)) Then proc.Kill() End If Next End If End Sub 
+5
Jan 21 '11 at 16:09
source share

Another way to use Powershell:

PS: I don’t know if anyone needs this, but I just accidentally came across this solution looking for something completely different.

0
Mar 28 '14 at 17:00
source share



All Articles