Browse Source

Allow external program to be run when starting web project.

Do not force the use of IIS or IIS Express to debug or run a web project.
Fix IIS Express always being debugged even if Run without debugger was
selected.
pull/39/merge
Matt Ward 13 years ago
parent
commit
eafe04b069
  1. 83
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/WebBehavior.cs

83
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/WebBehavior.cs

@ -30,6 +30,16 @@ namespace ICSharpCode.AspNet.Mvc
set { SetProjectProperty("StartURL", value); } set { SetProjectProperty("StartURL", value); }
} }
public string StartArguments {
get { return GetProjectProperty("StartArguments"); }
set { SetProjectProperty("StartArguments", value); }
}
public string StartWorkingDirectory {
get { return GetProjectProperty("StartWorkingDirectory"); }
set { SetProjectProperty("StartWorkingDirectory", value); }
}
string GetProjectProperty(string name) string GetProjectProperty(string name)
{ {
return MSBuildProject.GetEvaluatedProperty(name) ?? String.Empty; return MSBuildProject.GetEvaluatedProperty(name) ?? String.Empty;
@ -37,7 +47,7 @@ namespace ICSharpCode.AspNet.Mvc
void SetProjectProperty(string name, string value) void SetProjectProperty(string name, string value)
{ {
MSBuildProject.SetProperty("StartProgram", String.IsNullOrEmpty(value) ? null : value); MSBuildProject.SetProperty(name, String.IsNullOrEmpty(value) ? null : value);
} }
MSBuildBasedProject MSBuildProject { MSBuildBasedProject MSBuildProject {
@ -68,38 +78,10 @@ namespace ICSharpCode.AspNet.Mvc
public override void Start(bool withDebugging) public override void Start(bool withDebugging)
{ {
if (!CheckWebProjectStartInfo())
return;
try { try {
WebProjectProperties properties = WebProject.GetWebProjectProperties(); WebProjectProperties properties = WebProject.GetWebProjectProperties();
string processName = WebProjectService.GetWorkerProcessName(properties); if (CheckWebProjectStartInfo()) {
AttachToWebWorkerProcessOrStartIISExpress(properties, withDebugging);
// try find the worker process directly or using the process monitor callback
Process[] processes = System.Diagnostics.Process.GetProcesses();
int index = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));
if (index > -1) {
if (withDebugging)
DebuggerService.CurrentDebugger.Attach(processes[index]);
} else {
if (properties.UseIISExpress) {
// start IIS express and attach to it
if (WebProjectService.IsIISExpressInstalled) {
ProcessStartInfo processInfo = IISExpressProcessStartInfo.Create(WebProject);
DebuggerService.CurrentDebugger.Start(processInfo);
} else {
DisposeProcessMonitor();
MessageService.ShowError("${res:ICSharpCode.WebProjectOptionsPanel.NoProjectUrlOrProgramAction}");
return;
}
} else {
DisposeProcessMonitor();
this.monitor = new ProcessMonitor(processName);
this.monitor.ProcessCreated += delegate {
WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(properties, withDebugging)));
};
this.monitor.Start();
}
} }
// start default application(e.g. browser) or the one specified // start default application(e.g. browser) or the one specified
@ -113,7 +95,12 @@ namespace ICSharpCode.AspNet.Mvc
} }
break; break;
case StartAction.Program: case StartAction.Program:
Process.Start(StartProgram); ProcessStartInfo processInfo = DotNetStartBehavior.CreateStartInfo(StartProgram, Project.Directory, StartWorkingDirectory, StartArguments);
if (withDebugging) {
DebuggerService.CurrentDebugger.Start(processInfo);
} else {
Process.Start(processInfo);
}
break; break;
case StartAction.StartURL: case StartAction.StartURL:
if (FileUtility.IsUrl(StartUrl)) { if (FileUtility.IsUrl(StartUrl)) {
@ -139,12 +126,42 @@ namespace ICSharpCode.AspNet.Mvc
} }
} }
void AttachToWebWorkerProcessOrStartIISExpress(WebProjectProperties properties, bool withDebugging)
{
string processName = WebProjectService.GetWorkerProcessName(properties);
// try find the worker process directly or using the process monitor callback
Process[] processes = System.Diagnostics.Process.GetProcesses();
int index = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));
if (index > -1) {
if (withDebugging)
DebuggerService.CurrentDebugger.Attach(processes[index]);
} else {
if (properties.UseIISExpress) {
// start IIS express and attach to it
if (WebProjectService.IsIISExpressInstalled) {
ProcessStartInfo processInfo = IISExpressProcessStartInfo.Create(WebProject);
if (withDebugging)
DebuggerService.CurrentDebugger.Start(processInfo);
else
Process.Start(processInfo);
}
} else {
DisposeProcessMonitor();
this.monitor = new ProcessMonitor(processName);
this.monitor.ProcessCreated += delegate {
WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(properties, withDebugging)));
};
this.monitor.Start();
}
}
}
bool CheckWebProjectStartInfo() bool CheckWebProjectStartInfo()
{ {
if (WebProject.HasWebProjectProperties() && WebProject.GetWebProjectProperties().IsConfigured()) { if (WebProject.HasWebProjectProperties() && WebProject.GetWebProjectProperties().IsConfigured()) {
return true; return true;
} }
MessageService.ShowError("${res:ICSharpCode.WebProjectOptionsPanel.NoProjectUrlOrProgramAction}");
return false; return false;
} }

Loading…
Cancel
Save