public virtual EnvDTE.Project AddFromFile(string fileName)
        {
            ProjectContainerNode projectContainer = (ProjectContainerNode)this.node.ProjectMgr;
            ProjectElement       newElement       = new ProjectElement(projectContainer, fileName, ProjectFileConstants.SubProject);
            NestedProjectNode    newNode          = projectContainer.AddExistingNestedProject(newElement, __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_OPENFILE);

            if (newNode == null)
            {
                return(null);
            }
            // Now that the sub project was created, get its extensibility object so we can return it
            object newProject = null;

            return(ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                if (ErrorHandler.Succeeded(newNode.NestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out newProject)))
                {
                    return newProject as EnvDTE.Project;
                }
                else
                {
                    return null;
                }
            }));
        }
        public virtual EnvDTE.Project AddFromTemplate(string fileName, string destination, string projectName)
        {
            bool isVSTemplate = Utilities.IsTemplateFile(fileName);

            NestedProjectNode newNode = null;

            ThreadHelper.ThrowIfNotOnUIThread();

            if (isVSTemplate)
            {
                // Get the wizard to run, we will get called again and use the alternate code path
                ProjectElement newElement = new ProjectElement(this.node.ProjectMgr, System.IO.Path.Combine(destination, projectName), ProjectFileConstants.SubProject);
                newElement.SetMetadata(ProjectFileConstants.Template, fileName);
                ((ProjectContainerNode)this.node.ProjectMgr).RunVsTemplateWizard(newElement, false);
            }
            else
            {
                if ((String.IsNullOrEmpty(System.IO.Path.GetExtension(projectName))))
                {
                    string targetExtension = System.IO.Path.GetExtension(fileName);
                    projectName = System.IO.Path.ChangeExtension(projectName, targetExtension);
                }

                ProjectContainerNode projectContainer = (ProjectContainerNode)this.node.ProjectMgr;
                newNode = projectContainer.AddNestedProjectFromTemplate(fileName, destination, projectName, null, __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_CLONEFILE);
            }
            if (newNode == null)
            {
                return(null);
            }

            // Now that the sub project was created, get its extensibility object so we can return it
            object newProject = null;

            if (ErrorHandler.Succeeded(newNode.NestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out newProject)))
            {
                return(newProject as EnvDTE.Project);
            }
            else
            {
                return(null);
            }
        }