public void ProjectFinishedGenerating(Project project)
        {
            if (selectedTypes != null)
            {
                string validationErrors = string.Empty;
                string itemPath         = null;
                string fileExtension    = null;

                EnvDTE80.Events2   objEvents2;
                EnvDTE80.Solution2 solution = project.DTE.Solution as EnvDTE80.Solution2;

                OutputWindowManager outPutWindowmng = new OutputWindowManager();

                // Subscribe all the IDE events
                envDTE     = project.DTE;
                objEvents2 = ((EnvDTE80.Events2)(envDTE.Events));

                // Subscribe the item added event
                projectItemsEvents            = objEvents2.ProjectItemsEvents;
                projectItemsEvents.ItemAdded += ProjectItemsEvents_ItemAdded;

                // Write the post-build command to register the assembly.
                if (VSOptionsValidator.CanCreatePostBuildEvent(ref validationErrors))
                {
                    // Build the command to call.
                    string erpPath = Path.Combine(GeneralOptions.Instance.Path, "RegisterExtension.exe");

                    if (File.Exists(erpPath))
                    {
                        // Add command-line parameters.
                        string command = $"Call {string.Format("\"{0}\"", erpPath)} " +
                                         $" {GeneralOptions.Instance.Company} {GeneralOptions.Instance.UserName}" +
                                         $" {GeneralOptions.Instance.Password} {GeneralOptions.Instance.ProductLine}" +
                                         $" $(TargetPath) {GeneralOptions.Instance.CommonExtension}";

                        EnvDTE.Properties configmg = project.Properties;
                        configmg.Item("PostBuildEvent").Value = command;

                        outPutWindowmng.WriteMessage("The post-build command was added to the project.", OutputWindowMessagesType.Message);

                        // Set start external program
                        string erpEpp = string.Format("Erp100L{0}.exe", GeneralOptions.Instance.ProductLine == 0 ? "E" : "P");

                        Configuration activeConfig = project.ConfigurationManager.ActiveConfiguration;
                        activeConfig.Properties.Item("StartAction").Value  = prjStartAction.prjStartActionProgram;
                        activeConfig.Properties.Item("StartProgram").Value = Path.Combine(GeneralOptions.Instance.Path, erpEpp);

                        outPutWindowmng.WriteMessage("The start external program was set.", OutputWindowMessagesType.Message);
                    }
                    else
                    {
                        StringBuilder msg = new StringBuilder();

                        msg.Append("The post-build command could not be registered. \n");
                        msg.Append("The command line utility does not exist on the folder.");
                        msg.Append(GeneralOptions.Instance.Path);
                        msg.Append("Download it from https://developers.primaverabss.com/v10/como-automatizar-registo-extensoes/ \n");

                        outPutWindowmng.WriteMessage(msg.ToString(), OutputWindowMessagesType.Error);
                    }
                }
                else
                {
                    outPutWindowmng.WriteMessage("The post-build event has not been configured because of the following validation issues:", OutputWindowMessagesType.Warning);
                    outPutWindowmng.WriteMessage(validationErrors, OutputWindowMessagesType.Message);
                    outPutWindowmng.WriteMessage("Check this on Tools | Options | PRIMAVERA Extensibility.", OutputWindowMessagesType.Message);
                }

                if (project.Kind == PrjKind.prjKindCSharpProject)
                {
                    itemPath      = solution.GetProjectItemTemplate("PriClass.zip", "CSharp");
                    fileExtension = ".cs";
                }
                else
                {
                    itemPath      = solution.GetProjectItemTemplate("PriClass.zip", "VisualBasic");
                    fileExtension = ".vb";
                }

                if (!String.IsNullOrEmpty(itemPath))
                {
                    // Add generic references
                    WizardHelper.AddBaseReferences(project, "Bas", GeneralOptions.Instance.Path);
                    WizardHelper.AddBaseReferences(project, "Ext", GeneralOptions.Instance.Path);

                    foreach (MyTreeNode type in selectedTypes)
                    {
                        this.SelectedNode = type;

                        ProjectItem rootFolder = project.ProjectItems.Cast <ProjectItem>()
                                                 .FirstOrDefault(i => i.Name == type.Module) ?? project.ProjectItems.AddFolder(type.Module);

                        // Add the module reference.
                        WizardHelper.AddModuleReference(project, "Primavera.Extensibility." + type.Module);

                        // Add dependencies to the select modules.
                        WizardHelper.AddDependenciesReference(project, type.Module);

                        switch (type.ModuleType)
                        {
                        case "Editors":
                            rootFolder.ProjectItems.AddFromTemplate(itemPath, "Ui" + type.ClassName + fileExtension);
                            break;

                        case "Services":
                            rootFolder.ProjectItems.AddFromTemplate(itemPath, "Api" + type.ClassName + fileExtension);
                            break;
                        }
                    }
                }

                outPutWindowmng.WriteMessage("The project was created with success.");

                // UnSubscribing event.
                projectItemsEvents.ItemAdded -= ProjectItemsEvents_ItemAdded;
            }
        }
        public void ProjectFinishedGenerating(Project project)
        {
            if (_selectedTypes != null)
            {
                string _validationErrors = string.Empty;
                string _itemPath         = null;
                string _fileExtension    = null;

                EnvDTE80.Events2   _objEvents2;
                EnvDTE80.Solution2 _solution = project.DTE.Solution as EnvDTE80.Solution2;

                OutputWindowManager outPutWindowmng = new OutputWindowManager();

                // Subscribe all the IDE events
                _envDTE     = project.DTE;
                _objEvents2 = ((EnvDTE80.Events2)(_envDTE.Events));

                // Write the post-build command to register the assembly.
                if (VSOptionsValidator.CanCreatePostBuildEvent(ref _validationErrors))
                {
                    // Add command-line parameters.
                    string command = $"copy /Y \"$(TargetPath)\" \"{WebApiOptions.Instance.Path}\\$(ProjectName).dll\"";

                    EnvDTE.Properties configmg = project.Properties;
                    configmg.Item("PostBuildEvent").Value = command;

                    outPutWindowmng.WriteMessage("The post-build command was added to the project.", OutputWindowMessagesType.Message);
                }
                else
                {
                    outPutWindowmng.WriteMessage("The post-build event has not been configured because of the following validation issues:", OutputWindowMessagesType.Warning);
                    outPutWindowmng.WriteMessage(_validationErrors, OutputWindowMessagesType.Message);
                    outPutWindowmng.WriteMessage("Check this on Tools | Options | PRIMAVERA Extensibility.", OutputWindowMessagesType.Message);
                }

                if (project.Kind == PrjKind.prjKindCSharpProject)
                {
                    _itemPath      = _solution.GetProjectItemTemplate("PriWebApiControler.zip", "CSharp");
                    _fileExtension = ".cs";
                }
                else
                {
                    _itemPath      = _solution.GetProjectItemTemplate("PriWebApiControler.zip", "VisualBasic");
                    _fileExtension = ".vb";
                }

                // Add folder to keep all controllers.
                ProjectItem rootFolder = project.ProjectItems.AddFolder("Controllers");

                // Add the class to the project.
                rootFolder.ProjectItems.AddFromTemplate(_itemPath, _controllerName + _fileExtension);

                // Add generic references
                //WizardHelper.AddApiBaseDependencies(project);
                WizardHelper.AddBaseReferences(project, "Bas", GeneralOptions.Instance.Path);
                WizardHelper.AddBaseReferences(project, "Api", WebApiOptions.Instance.Path);

                // Add references to the select modules
                foreach (TreeNode type in _selectedTypes)
                {
                    if (!String.IsNullOrEmpty(_itemPath))
                    {
                        // Add dependencies to the select modules.
                        WizardHelper.AddDependenciesReference(project, type.Text);
                    }
                }

                outPutWindowmng.WriteMessage("The project was created with success.");
            }
        }