Search code examples
visual-studioenvdte

How to shutdown Visual Studio process started by EnvDTE


I have written a console app that uses EnvDTE to process 10 or so solutions and refactor them programmatically - changing references and project structure

        var envDteType = Type.GetTypeFromProgID("VisualStudio.DTE.15.0");

        var envDte = Activator.CreateInstance(envDteType, true);
        var dte2 = (DTE2)envDte;

        var solution = (Solution4)dte2.Solution;
        solution.Open(filename);

        // execute various tasks

        solution.Close();
        // how to dispose of dte2?

The trick is, when my app finishes there are Visual Studio processes still running presumably opened by EnvDTE. I shutdown my only Visual Studio instance visibly running and they persist.

Is there a way to shutdown those processes that the EnvDTE object spawned?

The following seems to have no effect

dte2.Application.ActiveWindow.Close();

Solution

  • Hans' is correct - dte2.Quit(); does the job