public void CleanUp()
        {
            if (_bDteInstanciated)
            {
                Func <bool> CloseSolutionAndDte = delegate()
                {
                    _dte.Solution.Close(_saveVolatileSln);
                    conlog.WriteLine("Closed " + _timeStampPrefix + "_" + _assemblyName + ".sln");
                    _dte.Quit();
                    return(true);
                };

                RetryCall.Do <bool>(CloseSolutionAndDte, TimeSpan.FromSeconds(_projRetryAfterSeconds), _projRetriesCount);
                conlog.WriteLine("Closed Visual Studio instance");
                _bDteInstanciated = false;
                // and turn off the IOleMessageFilter
                MessageFilter.Revoke();
                conlog.CloseLogging();

                //_dte.Solution.Close(_saveVolatileSln);
                //conlog.WriteLine("Closed " + _timeStampPrefix + "_" + _assemblyName + ".sln");
                //_dte.Quit();
                //conlog.WriteLine("Closed Visual Studio instance");
                //_bDteInstanciated = false;
                //// and turn off the IOleMessageFilter
                //// MessageFilter.Revoke();
                //conlog.CloseLogging();
            }
        }
        public bool ExtractProjectData(string projPath, ref ExtractedProjData projData)
        {
            try
            {
                if (!conlog.IsInitialized())
                {
                    // initialize logger again if necessary
                    conlog.InitLogging(_outModeLogging, _strLogPath + "\\" + _timeStampPrefix + "_" + _assemblyName + ".log");
                }
                // load project by silently automating the Visual Studio installation specified by the major version
                if (!_bDteInstanciated)
                {
                    string VisualStudioDTEVerString = String.Format("VisualStudio.DTE.{0}.0", _VS_MajorVersion);
                    Type   visualStudioType         = Type.GetTypeFromProgID(VisualStudioDTEVerString);
                    _dte = Activator.CreateInstance(visualStudioType) as DTE;

                    // Register the IOleMessageFilter to handle any threading errors
                    MessageFilter.Register();

                    _dte.MainWindow.Visible = false;
                    _dte.SuppressUI         = true;
                    _dte.UserControl        = false;
                    conlog.WriteLine("Instanciated " + VisualStudioDTEVerString);

                    _dte.Solution.Create(Path.GetTempPath(), _timeStampPrefix + "_" + _assemblyName + ".sln");
                    _bDteInstanciated = true;

                    // wait 5 more seconds TODO: check again  at some point, if this can be done more elegant by registering a message filter to
                    // handle busy call errors https://docs.microsoft.com/en-us/previous-versions/ms228772(v=vs.140)?redirectedfrom=MSDN
                    System.Threading.Thread.Sleep(1000 * _solutionSleepAfterCreate);
                    conlog.WriteLine(_assemblyName + ".sln created");
                }

                // add project to retrieve its type Guid and configurations if possible
                if (_bDteInstanciated)
                {
                    // retry loading the project into solution several times, because sometimes at the first attempt we might get
                    // System.Runtime.InteropServices.COMException with RPC_E_SERVERCALL_RETRYLATER
                    Func <string, EnvDTE.Project> AddProjectFromFile = delegate(string path)
                    {
                        Project projLoaded = _dte.Solution.AddFromFile(path);
                        conlog.WriteLine("Project '" + path + "' loaded into " + _timeStampPrefix + "_" + _assemblyName + ".sln");
                        return(projLoaded);
                    };
                    EnvDTE.Project myLoadedProject = RetryCall.Do <string>(AddProjectFromFile, projPath, TimeSpan.FromSeconds(_projRetryAfterSeconds), _projRetriesCount);
                    projData._TypeGuid = myLoadedProject.Kind.ToString();
                    EnvDTE.Configurations projectConfigurations;
                    foreach (object projectConfigurationName in (object[])myLoadedProject.ConfigurationManager.ConfigurationRowNames)
                    {
                        projectConfigurations = myLoadedProject.ConfigurationManager.ConfigurationRow(projectConfigurationName.ToString());
                        foreach (EnvDTE.Configuration projectConfiguration in projectConfigurations)
                        {
                            projData.AddConfigPlatform(projectConfiguration.ConfigurationName, projectConfiguration.PlatformName);
                        }
                    }
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                conlog.WriteLine("\n{0}\noccured for project file '{1}' loaded in Visual Studio {2}", ex.ToString(), projPath, _VS_MajorVersion);
                return(false);
            }
        }