/// <summary> /// Given a source and a destination, this function creates a new project, optionally performing code /// extraction upon it. A return of false means that either the project could not be created or /// there was an error with the extraction process. /// </summary> /// <param name="sourceUniqueProjectName"> The 'uniquename' property of the project to retrieve params from</param> /// <param name="path"> Output path, UNC / file paths only</param> /// <param name="destProjectName"> Name of the project to create </param> /// <param name="performExtraction"> Whether or not to extract properly-delimited sections of text from the source</param> public bool CreateNewProject(string sourceUniqueProjectName, string path, string destProjectName, bool performExtraction) { bool fSucceeded = true; if (sourceUniqueProjectName == null) { throw new System.ArgumentNullException("sourceUniqueProjectName"); } if (path == null) { throw new System.ArgumentNullException("path"); } if (destProjectName == null) { throw new System.ArgumentNullException("destProjectName"); } string strProjDestUniqueName = null; EnvDTE.Project projDest = null; EnvDTE.Project projSource = null; EnvDTE._DTE dteOutOfProcess = null; try { // if (m_taskWindow == null) { // m_taskWindow = new TaskWindow.DelayLoadTaskWindow(m_application); // } projSource = GetValidProject(sourceUniqueProjectName); if (projSource == null) { throw new Exception(AMResources.GetLocalizedString("CodeExtractorNoBaseProject")); } // NOTE: This is a method in the docs, but a property in implementation. object ignore = m_application.ItemOperations.PromptToSave; dteOutOfProcess = (EnvDTE._DTE) new VisualStudio_DTE_7_1(); projDest = CopyProject(projSource, dteOutOfProcess, path, destProjectName); if (projDest == null) { throw new Exception(AMResources.GetLocalizedString("CodeExtractorInvalidProjectType")); } strProjDestUniqueName = projDest.UniqueName; if (performExtraction) { // Perform extraction - on first user error, open handle to task-list. Log all errors to it. if (!ExtractItems(projSource.ProjectItems, dteOutOfProcess, projDest.ProjectItems)) { throw new Exception(AMResources.GetLocalizedString("CodeExtractorInvalidMarkedTags")); } } } finally { if ((dteOutOfProcess != null) && (dteOutOfProcess != m_application)) { // The solution has to be closed because if we're out of process, the // application might not close for a little while, leaving around // extant 'file opened exclusively' problems. dteOutOfProcess.Solution.Close(false); dteOutOfProcess.Quit(); dteOutOfProcess = null; } } return(fSucceeded); }
internal void getProjectFileInfo(string fileName, out string name, out string outputFile, out string configurationName, out string buildPath) { EnvDTE._DTE dte = null; EnvDTE.Configuration config = null; string Name, OutputFile, ConfigurationName, BuildPath; buildPath = String.Empty; configurationName = String.Empty; outputFile = String.Empty; name = String.Empty; try { EnvDTE.Project proj = null; EnvDTE.OutputGroup group = null; string outputURLDir, projectFileDir; Object[] OutputFiles = null; Object[] OutputURLs = null; int nIndex; dte = (EnvDTE._DTE) new VisualStudio_DTE_7_1(); dte.Solution.AddFromFile(fileName, false); proj = dte.Solution.Projects.Item(1); Name = proj.Name; config = proj.ConfigurationManager.ActiveConfiguration; ConfigurationName = config.ConfigurationName; // Loop through the possibly-many set of output groups, looking for the // one that has the build output. If we don't can't locate it, we will // attempt to use the first one in the list. nIndex = config.OutputGroups.Count; do { group = config.OutputGroups.Item(nIndex); nIndex--; } while ((nIndex > 0) && (group.CanonicalName != "Built")); OutputFiles = (Object[])group.FileNames; OutputFile = (string)OutputFiles[0]; OutputURLs = (Object[])group.FileURLs; outputURLDir = (string)OutputURLs[0]; // Given a full URL to the file path (file://c:\....) and the base path // to the project file (c:\...), determine the set of additional directories // into which the build is being performed. projectFileDir = getPath(fileName); projectFileDir = projectFileDir.ToUpper(); outputURLDir = outputURLDir.ToUpper(); nIndex = outputURLDir.LastIndexOf(projectFileDir); BuildPath = outputURLDir.Substring(nIndex + projectFileDir.Length); BuildPath = getPath(BuildPath); name = Name; outputFile = OutputFile; configurationName = ConfigurationName; buildPath = BuildPath; } catch (System.Exception) { throw new System.Exception(SharedSupport.GetLocalizedString("ProjectInfo_ProjFileInvalid")); } finally { if (dte != null) { try { dte.Solution.Close(false); dte.Quit(); } catch (System.Exception) { // Ignore errors when shutting down out-of-process IDE. } } } }