Le seul moyen que je connaisse est de faire un démarrage personnalisé de Cassini sur l'événement post.build. Ce processus personnalisé tue toutes les instances de Cassini, et en démarre une nouvelle. Afin que cela fonctionne, vous aurez besoin de construire un petit utilitaire de ligne de commande personnalisé. Je l'ai appelé SpawnProcess ici.
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());
}
}
}
}
}
}
Vous devrez alors demander à Visual Studio de ne pas utiliser Cassini. Allez dans les propriétés de votre application web -> Web et sélectionnez "Use Custom Web Server", entrez quelque chose comme : http://localhost:1685/
(ou tout autre numéro de port que vous souhaitez utiliser). Ensuite, entrez cette commande dans l'événement post-construction :
"$(ProjectDir)..\SpawnProc\bin\debug\SpawnProc" "C:\Program Files (x86)\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.exe" 1685 "$(ProjectDir)" /
Assurez-vous que vos chemins d'accès sont corrects, par exemple, puisque j'utilise un système d'exploitation 64 bits, le chemin d'accès à mes fichiers de programmes est différent de celui d'un système d'exploitation 32 bits. De plus, mon SpawnProc.exe est dans un sous-projet.