Exemplo n.º 1
0
        // This method is called after the project is created.
        public void RunFinished()
        {
            if (this.project != null)
            {
                /* If package.json is included in the project, the npm package manager automatically starts installing packages after project creation.
                 * An install can also be triggered by opening, saving and closing package.json.
                 * The problem is those features are controled by two independant settings.
                 * We may potentially trigger the npm installer twice. Apparently runs one instance, in very-very rare cases two.
                 * There were errors logged couple times in the Output window which looked like a racing conflict.
                 */
                // Trigger the npm package manager built-in in Visual Studio to start installing packages.
                EnvDTE.Window packageJsonWindow = null;
                if (!this.skipNpmInstall)
                {
                    var packageJsonItem     = FindProjectItem(this.project, packageJsonFileName);
                    var packageJsonFilePath = GetProjectItemExistingFilePath(packageJsonItem);
                    if (packageJsonFilePath != null)
                    {
                        packageJsonWindow = packageJsonItem.Open();
                        packageJsonWindow.Activate();
                        packageJsonItem.Save();
                    }
                }

                // Display README.md
                var readmeMdItem     = FindProjectItem(this.project, readmeMdFileName);
                var readmeMdFilePath = GetProjectItemExistingFilePath(readmeMdItem);
                if (readmeMdFilePath != null)
                {
                    var readmeMdWindow = readmeMdItem.Open();
                    readmeMdWindow.Activate();
                }

                // To avoid flicker, postpone closing package.json until after README.md has opened.
                if (packageJsonWindow != null)
                {
                    packageJsonWindow.Close();
                }

                // Close the ASP.NET Core project's default page. It has sections Overview, Connected Services, Publish.
                var windows = project.DTE.Windows;
                foreach (var w in windows)
                {
                    if (w is Window window)
                    {
                        if ((window.Type == vsWindowType.vsWindowTypeDocument) && (window.Caption == project.Name))
                        {
                            window.Close(vsSaveChanges.vsSaveChangesNo);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static bool close(this EnvDTE.Window window)
 {
     try
     {
         window.Close();                 //will throw exeption if window has been closed
         return(true);
     }
     catch (Exception ex)
     {
         ex.log("[in EnvDTE.window.close]");
         return(false);
     }
 }