public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary,
                               WizardRunKind runKind, object[] customParams)
        {
            string destinationDirectory = null;
            string solutionDirectory    = null;

            try
            {
                replacementsDictionary.TryGetValue("$safeprojectname$", out string projectName);
                replacementsDictionary.TryGetValue("$destinationdirectory$", out destinationDirectory);
                replacementsDictionary.TryGetValue("$solutiondirectory$", out solutionDirectory);

                // Test if @angular/cli is installed globally.
                this.isNgFound = NgWizardHelper.IsNgFound(solutionDirectory);

                // Display the wizard to the user.
                var viewModel  = new NgProjectWizardViewModel(projectName, this.isNgFound);
                var mainWindow = new NgProjectWizardWindow(viewModel);
                var accepted   = mainWindow.ShowDialog().GetValueOrDefault();

                this.skipNpmInstall = viewModel.SkipNpmInstall;
                // If package.json is included in the project, the npm package manager automatically starts installing packages after project creation.
                replacementsDictionary.Add("$includepackagejson$", this.skipNpmInstall ? String.Empty : includePackageJsonElement);

                this.addRouting = viewModel.AddRouting;

                if (!accepted)
                {
                    throw new WizardCancelledException("The wizard has been cancelled by the user.");
                }
            }
            catch
            {
                DateTime projectDirCreationTime = DateTime.MinValue;
                if (Directory.Exists(destinationDirectory))
                {
                    projectDirCreationTime = Directory.GetCreationTimeUtc(destinationDirectory);
                    Directory.Delete(destinationDirectory, true);
                }
                if (Directory.Exists(solutionDirectory))
                {
                    // The solution could exist before the template started.
                    // This is a poor man's method of deciding whether the solution dir was created at about the same time as the project dir.
                    var solutionDirCreationTime = Directory.GetCreationTimeUtc(solutionDirectory);
                    if (Math.Abs((projectDirCreationTime - solutionDirCreationTime).TotalSeconds) < 5)
                    {
                        Directory.Delete(solutionDirectory, true);
                    }
                }
                throw;
            }
        }
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary,
                               WizardRunKind runKind, object[] customParams)
        {
            replacementsDictionary.TryGetValue("$solutiondirectory$", out string solutionDirectory);

            var settings = new NgItemWizardViewModel.NgItemWizardSettings();

            // Test if @angular/cli is installed globally.
            this.isNgFound     = NgWizardHelper.IsNgFound(solutionDirectory);
            settings.IsNgFound = this.isNgFound;

            var dte            = (DTE)automationObject;
            var activeProjects = (Array)dte.ActiveSolutionProjects;

            if (activeProjects.Length > 0)
            {
                var project = (Project)activeProjects.GetValue(0);

                // The NuGet package needs netstandard2.0. We don't support ASP.NET Core 1.x projects.
                settings.IsAspNetCore2 = NgWizardHelper.IsAspNetCore2(project);
                // Look for an existing .angular-cli.json indicating there has been already an Angular CLI app created.
                settings.IsAngularCliJsonFound = NgWizardHelper.FindFileInRootDir(project, NgWizardHelper.AngularCliJsonFileName);
                // Test if a package.json exists.
                settings.IsOldPackageJsonFound = NgWizardHelper.FindFileInRootDir(project, NgWizardHelper.PackageJsonFileName, out string packageJsonFilePath);
                // Test if an entry for "@angular/core" exists in package.json.
                settings.IsNpmAngularFound = NgWizardHelper.IsNpmAngularFound(packageJsonFilePath);

                // Automatic installation is disabled if .gitignore or package.json or tsconfig.json or Startup.cs is opened in an editor window.
                settings.IsGitignoreOpened    = NgWizardHelper.IsFileOpened(project, NgWizardHelper.GitignoreFileName);
                settings.IsPackageJsonOpened  = NgWizardHelper.IsFileOpened(project, NgWizardHelper.PackageJsonFileName);
                settings.IsStartupCsOpened    = NgWizardHelper.IsFileOpened(project, NgWizardHelper.StartupCsFileName);
                settings.IsTsconfigJsonOpened = NgWizardHelper.IsFileOpened(project, NgWizardHelper.TsconfigJsonFileName);
            }

            // Display the wizard to the user.
            var viewModel  = new NgItemWizardViewModel(settings);
            var mainWindow = new NgItemWizardWindow(viewModel);
            var accepted   = mainWindow.ShowDialog().GetValueOrDefault();

            this.installAutomatically = viewModel.InstallAutomatically;

            if (!accepted)
            {
                throw new WizardCancelledException("The wizard has been cancelled by the user.");
            }
        }