Answered Custom project : Enter in debug mode then stop

  • Saturday, September 15, 2012 11:51 AM
     
     

    Hi,

    I am building a visual extension with a custom project and language service to support a javascript language. Now I would like when I click on "Start Debugging" button to launch a local webserver, start a IE instance and Visual enters in debug mode.

    Then when I click on "Stop Debugging" or close the IE instance I want the server to be stopped.

    How can I do that ?

    For the moment I am overriding the DebugLaunch method to start a web instance but it doesn't allow me to set Visual into debug state.

    Thanks

All Replies

  • Saturday, September 15, 2012 12:48 PM
     
      Has Code

    Actually I found some information and now I am doing this :

    public override int DebugLaunch(uint flags)
        {
                VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();
                dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);
                dbgInfo.dlo = (DEBUG_LAUNCH_OPERATION)_DEBUG_LAUNCH_OPERATION3.DLO_LaunchBrowser;
                dbgInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd | (uint)__VSDBGLAUNCHFLAGS4.DBGLAUNCH_UseDefaultBrowser;
              //...
    
                _project.StartWebServerInstance(dbgInfo);
                return VSConstants.S_OK;
        }

    Then inside my ProjectNode class : 

    public string StartWebServerInstance(VsDebugTargetInfo info)
        {
            ProcessStartInfo psi;
            string path, outputPath;
            int serverPort = 12346, uniqueId;
    
            //...
    
            webServerInstance = new Process();
            psi = webServerInstance.StartInfo;
            psi.FileName = webServerPath;
            psi.Arguments = String.Format(CultureInfo.InvariantCulture,
                "/port:{0} /path:\"{1}\" /vpath:\"/CappApplication_{2}\"", serverPort, outputPath, uniqueId);
            psi.WorkingDirectory = outputPath;
            psi.UseShellExecute = false;
    
            webServerInstance.Start();
            webServerInstance.WaitForInputIdle(30000);
    
            outputPath = String.Format(CultureInfo.InvariantCulture,
                       "http://localhost:{0}/CappApplication_{1}/index.html", serverPort, uniqueId);
    
            return outputPath;
        }

    and the web server is started but now the question is how can I launch a browser instance that depends on debugger ?

    When the server is started I get a notification window, ASP .Net Server and then I can right click on it and then select Open in browser. Then I have to choose index.html.

    I would like to simplify all these steps and provide the same user experience as a standard web project.

  • Monday, September 17, 2012 8:43 AM
     
     
    Do you want to launch a browser when you debugger?

    Or you want to debug the browser?
  • Monday, September 17, 2012 10:11 AM
     
     

    I want to do exactly the same as when debugging a MVC3 Web application, when you press F5 (or click 'Start Debug')it starts a local webserver and a browser. When you close the browser it stops the debug mode.

  • Tuesday, September 18, 2012 9:22 AM
    Moderator
     
     

    Hi Vincent,

    I will involve some experts into this issue to see whether they can help you out. There might be some time delay, appreciate for your patience.
     
    Thank you for your understanding and support.
     
    Best regards,

    Ego


    Ego [MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, September 25, 2012 10:03 PM
    Moderator
     
     Answered

    Hi Vincent,

    The easiest way to do this would be with a project subtype, where you'd just let the WAP project type handle the launch. But if you're dealing with a different project type entirely, then you do have to handle the launch via your DebugLaunch implementation.

    The WebApp project type actually prelaunches Cassini by calling LaunchDebugTargets3 to kick off the WebDev.WebServer40.exe process (storing away the processID and creationTime from the VsDebugTargetProcessInfo arg.

    Once it's running, the project type then retrieves the launch targets for the server and browser, and then invokes LaunchDebugTargets3 again with 2 VsDebugTargetInfo3 objects.

    At least that's what it looks like when you set a breakpoint on vsdebug.dll!CDebugger::LaunchDebugTargets3 and then launch the debugger against an MVC3 project.

    As to which flags are set on each VsDebugTargetInfo3, on each invocation of LaunchDebugTargets3, that can probably be figured out by attaching WinDBG to devenv.exe, and setting a BP on said vsdebug!CDebugger::LaunchDebugTargets3 and examining the arguments that are pass in.

    Sincerely,


    Ed Dore