locked
calling IVsShell4.Restart programatically RRS feed

  • Question

  • Hi all,

    I am working on a VS addin in which I need VS to be restarted in some point. I came across with  IVsShell4.Restart and I though that it would work in the same way I'm using IVsShell methods but after running:

    var obj = (IVsShell4)this.GetService (typeof (IVsShell4));
    (obj as IVsShell4).Restart ((uint)__VSRESTARTTYPE.RESTART_Normal);
    

    obj object always is null. What am I missing? is it possible to restart VS progamatically? I guess Addin manager uses such method...

    thanks in advance...

    josemiguel


    José Miguel Torres

    Thursday, November 8, 2012 8:28 PM

Answers

  • Requesting services via a semi-random inteface GUID is a bad practice, I know it is endemic in 'samples', but it is still wrong :) In this case you likely want to do something like this

    var obj = (IVsShell4)this.GetService(typeof(SVsShell));

    services are registered under a specific GUID. Those services may well implement many interfaces. Those two things are orthogonal. Service ID interfaces are generally S<interface name> in VS. The only significant deviation from that is the (annoying) IVsMonitorSelection/SVsShellMonitorSelection pairing.

    Ryan

    Thursday, November 8, 2012 8:57 PM
  • If VS didn't restart after you called Restart it means either it is in a place where it doesn't think it can close for some reason or the user cancelled the restart request. If either of those occured you using Process.Kill would be a horrible idea. What scenario are you seeing where after calling Restart the shell is not restarting? Is Restart returning a failure code?

    Ryan

    Thursday, November 8, 2012 11:25 PM

All replies

  • Requesting services via a semi-random inteface GUID is a bad practice, I know it is endemic in 'samples', but it is still wrong :) In this case you likely want to do something like this

    var obj = (IVsShell4)this.GetService(typeof(SVsShell));

    services are registered under a specific GUID. Those services may well implement many interfaces. Those two things are orthogonal. Service ID interfaces are generally S<interface name> in VS. The only significant deviation from that is the (annoying) IVsMonitorSelection/SVsShellMonitorSelection pairing.

    Ryan

    Thursday, November 8, 2012 8:57 PM
  • Thanks Ryan, just one more question.

    I guess Process.GetCurrentProcess ().Kill (); is not the best approach after calling IVsShell4.Restart method in order to force VS to close . Does the VS Shell expose any kind of method in order to Exit VS as we do by clicking File -> Exit?

    thanks again,,

    cheers,

    josemiguel


    José Miguel Torres

    Thursday, November 8, 2012 10:31 PM
  • If VS didn't restart after you called Restart it means either it is in a place where it doesn't think it can close for some reason or the user cancelled the restart request. If either of those occured you using Process.Kill would be a horrible idea. What scenario are you seeing where after calling Restart the shell is not restarting? Is Restart returning a failure code?

    Ryan

    Thursday, November 8, 2012 11:25 PM
  • There was a modal windows preventing VS to restart. You were right. After closing it IVsShell4.Restart works perfectly. In both cases Restart returned VSConstants.S_OK, however.

    Thank you very much for your help Ryan,,

    Best regards,

    josemiguel


    José Miguel Torres

    Friday, November 9, 2012 8:07 AM