Пример #1
0
        public ISolution CreateEmptySolutionFile(FileName fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (fileName.IsRelative)
            {
                throw new ArgumentException("Path must be rooted!");
            }
            Solution solution = new Solution(fileName, new ProjectChangeWatcher(fileName), SD.FileService);

            solution.LoadPreferences();
            return(solution);
        }
Пример #2
0
		public ISolution CreateEmptySolutionFile(FileName fileName)
		{
			if (fileName == null)
				throw new ArgumentNullException("fileName");
			if (fileName.IsRelative)
				throw new ArgumentException("Path must be rooted!");
			Solution solution = new Solution(fileName, new ProjectChangeWatcher(fileName), SD.FileService);
			solution.LoadPreferences();
			return solution;
		}
Пример #3
0
        public void ReadSolution(Solution solution, IProgressMonitor progress)
        {
            ReadFormatHeader();
            ReadVersionProperties(solution);

            // Read solution folder and project entries:
            var  solutionEntries    = new List <ProjectLoadInformation>();
            var  projectInfoDict    = new Dictionary <Guid, ProjectLoadInformation>();
            var  solutionFolderDict = new Dictionary <Guid, SolutionFolder>();
            int  projectCount       = 0;
            bool fixedGuidConflicts = false;

            ProjectLoadInformation information;

            while ((information = ReadProjectEntry(solution)) != null)
            {
                solutionEntries.Add(information);
                if (projectInfoDict.ContainsKey(information.IdGuid))
                {
                    // resolve GUID conflicts
                    SD.Log.WarnFormatted("Detected duplicate GUID in .sln file: {0} is used for {1} and {2}", information.IdGuid, information.ProjectName, projectInfoDict[information.IdGuid].ProjectName);
                    information.IdGuid = Guid.NewGuid();
                    fixedGuidConflicts = true;
                }
                projectInfoDict.Add(information.IdGuid, information);

                if (information.TypeGuid == ProjectTypeGuids.SolutionFolder)
                {
                    solutionFolderDict.Add(information.IdGuid, CreateSolutionFolder(solution, information));
                }
                else
                {
                    projectCount++;
                }
            }

            progress.CancellationToken.ThrowIfCancellationRequested();

            // Read global sections:
            if (currentLine != "Global")
            {
                if (currentLine == null)
                {
                    throw Error("Unexpected end of file");
                }
                else
                {
                    throw Error("Unknown line: " + currentLine);
                }
            }
            NextLine();

            Dictionary <Guid, SolutionFolder> guidToParentFolderDict = null;

            SolutionSection section;

            while ((section = ReadSection(isGlobal: true)) != null)
            {
                switch (section.SectionName)
                {
                case "SolutionConfigurationPlatforms":
                    var configurations = LoadSolutionConfigurations(section);
                    foreach (var config in configurations.Select(c => c.Configuration).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
                    {
                        solution.ConfigurationNames.Add(config, null);
                    }
                    foreach (var platform in configurations.Select(c => c.Platform).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
                    {
                        solution.PlatformNames.Add(platform, null);
                    }
                    break;

                case "ProjectConfigurationPlatforms":
                    LoadProjectConfigurations(section, projectInfoDict);
                    break;

                case "NestedProjects":
                    guidToParentFolderDict = LoadNesting(section, solutionFolderDict);
                    break;

                default:
                    solution.GlobalSections.Add(section);
                    break;
                }
            }
            if (currentLine != "EndGlobal")
            {
                throw Error("Expected 'EndGlobal'");
            }
            NextLine();
            if (currentLine != null)
            {
                throw Error("Expected end of file");
            }

            solution.LoadPreferences();

            // Now that the project configurations have been set, we can actually load the projects:
            int projectsLoaded = 0;

            foreach (var projectInfo in solutionEntries)
            {
                // Make copy of IdGuid just in case the project binding writes to projectInfo.IdGuid
                Guid          idGuid = projectInfo.IdGuid;
                ISolutionItem solutionItem;
                if (projectInfo.TypeGuid == ProjectTypeGuids.SolutionFolder)
                {
                    solutionItem = solutionFolderDict[idGuid];
                }
                else
                {
                    // Load project:
                    projectInfo.ActiveProjectConfiguration = projectInfo.ConfigurationMapping.GetProjectConfiguration(solution.ActiveConfiguration);
                    progress.TaskName = "Loading " + projectInfo.ProjectName;
                    using (projectInfo.ProgressMonitor = progress.CreateSubTask(1.0 / projectCount)) {
                        solutionItem = LoadProjectWithErrorHandling(projectInfo);
                    }
                    if (solutionItem.IdGuid != idGuid)
                    {
                        Guid projectFileGuid = solutionItem.IdGuid;
                        if (!projectInfoDict.ContainsKey(projectFileGuid))
                        {
                            // We'll use the GUID from the project file.
                            // Register that GUID in the dictionary to avoid its use by multiple projects.
                            projectInfoDict.Add(projectFileGuid, projectInfo);
                        }
                        else
                        {
                            // Cannot use GUID from project file due to conflict.
                            // To fix the problem without potentially introducing new conflicts in other .sln files that contain the project,
                            // we generate a brand new GUID:
                            solutionItem.IdGuid = Guid.NewGuid();
                        }
                        SD.Log.WarnFormatted("<ProjectGuid> in project '{0}' is '{1}' and does not match the GUID stored in the solution ({2}). "
                                             + "The conflict was resolved using the GUID {3}",
                                             projectInfo.ProjectName, projectFileGuid, idGuid, solutionItem.IdGuid);
                        fixedGuidConflicts = true;
                    }
                    projectsLoaded++;
                    progress.Progress = (double)projectsLoaded / projectCount;
                }
                // Add solutionItem to solution:
                SolutionFolder folder;
                if (guidToParentFolderDict != null && guidToParentFolderDict.TryGetValue(idGuid, out folder))
                {
                    folder.Items.Add(solutionItem);
                }
                else
                {
                    solution.Items.Add(solutionItem);
                }
            }

            solution.IsDirty = fixedGuidConflicts;             // reset IsDirty=false unless we've fixed GUID conflicts
        }
Пример #4
0
		public void ReadSolution(Solution solution, IProgressMonitor progress)
		{
			ReadFormatHeader();
			ReadVersionProperties(solution);
			
			// Read solution folder and project entries:
			var solutionEntries = new List<ProjectLoadInformation>();
			var projectInfoDict = new Dictionary<Guid, ProjectLoadInformation>();
			var solutionFolderDict = new Dictionary<Guid, SolutionFolder>();
			int projectCount = 0;
			bool fixedGuidConflicts = false;
			
			ProjectLoadInformation information;
			while ((information = ReadProjectEntry(solution)) != null) {
				solutionEntries.Add(information);
				if (projectInfoDict.ContainsKey(information.IdGuid)) {
					// resolve GUID conflicts
					SD.Log.WarnFormatted("Detected duplicate GUID in .sln file: {0} is used for {1} and {2}", information.IdGuid, information.ProjectName, projectInfoDict[information.IdGuid].ProjectName);
					information.IdGuid = Guid.NewGuid();
					fixedGuidConflicts = true;
				}
				projectInfoDict.Add(information.IdGuid, information);
				
				if (information.TypeGuid == ProjectTypeGuids.SolutionFolder) {
					solutionFolderDict.Add(information.IdGuid, CreateSolutionFolder(solution, information));
				} else {
					projectCount++;
				}
			}
			
			progress.CancellationToken.ThrowIfCancellationRequested();
			
			// Read global sections:
			if (currentLine != "Global") {
				if (currentLine == null)
					throw Error("Unexpected end of file");
				else
					throw Error("Unknown line: " + currentLine);
			}
			NextLine();
			
			Dictionary<Guid, SolutionFolder> guidToParentFolderDict = null;
			
			SolutionSection section;
			while ((section = ReadSection(isGlobal: true)) != null) {
				switch (section.SectionName) {
					case "SolutionConfigurationPlatforms":
						var configurations = LoadSolutionConfigurations(section);
						foreach (var config in configurations.Select(c => c.Configuration).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
							solution.ConfigurationNames.Add(config, null);
						foreach (var platform in configurations.Select(c => c.Platform).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
							solution.PlatformNames.Add(platform, null);
						break;
					case "ProjectConfigurationPlatforms":
						LoadProjectConfigurations(section, projectInfoDict);
						break;
					case "NestedProjects":
						guidToParentFolderDict = LoadNesting(section, solutionFolderDict);
						break;
					default:
						solution.GlobalSections.Add(section);
						break;
				}
			}
			if (currentLine != "EndGlobal")
				throw Error("Expected 'EndGlobal'");
			NextLine();
			if (currentLine != null)
				throw Error("Expected end of file");
			
			solution.LoadPreferences();
			
			// Now that the project configurations have been set, we can actually load the projects:
			int projectsLoaded = 0;
			foreach (var projectInfo in solutionEntries) {
				// Make copy of IdGuid just in case the project binding writes to projectInfo.IdGuid
				Guid idGuid = projectInfo.IdGuid;
				ISolutionItem solutionItem;
				if (projectInfo.TypeGuid == ProjectTypeGuids.SolutionFolder) {
					solutionItem = solutionFolderDict[idGuid];
				} else {
					// Load project:
					projectInfo.ActiveProjectConfiguration = projectInfo.ConfigurationMapping.GetProjectConfiguration(solution.ActiveConfiguration);
					progress.TaskName = "Loading " + projectInfo.ProjectName;
					using (projectInfo.ProgressMonitor = progress.CreateSubTask(1.0 / projectCount)) {
						solutionItem = LoadProjectWithErrorHandling(projectInfo);
					}
					if (solutionItem.IdGuid != idGuid) {
						Guid projectFileGuid = solutionItem.IdGuid;
						if (!projectInfoDict.ContainsKey(projectFileGuid)) {
							// We'll use the GUID from the project file.
							// Register that GUID in the dictionary to avoid its use by multiple projects.
							projectInfoDict.Add(projectFileGuid, projectInfo);
						} else {
							// Cannot use GUID from project file due to conflict.
							// To fix the problem without potentially introducing new conflicts in other .sln files that contain the project,
							// we generate a brand new GUID:
							solutionItem.IdGuid = Guid.NewGuid();
						}
						SD.Log.WarnFormatted("<ProjectGuid> in project '{0}' is '{1}' and does not match the GUID stored in the solution ({2}). "
						                     + "The conflict was resolved using the GUID {3}",
						                     projectInfo.ProjectName, projectFileGuid, idGuid, solutionItem.IdGuid);
						fixedGuidConflicts = true;
					}
					projectsLoaded++;
					progress.Progress = (double)projectsLoaded / projectCount;
				}
				// Add solutionItem to solution:
				SolutionFolder folder;
				if (guidToParentFolderDict != null && guidToParentFolderDict.TryGetValue(idGuid, out folder)) {
					folder.Items.Add(solutionItem);
				} else {
					solution.Items.Add(solutionItem);
				}
			}
			
			solution.IsDirty = fixedGuidConflicts; // reset IsDirty=false unless we've fixed GUID conflicts
		}
Пример #5
0
		public void ReadSolution(Solution solution, IProgressMonitor progress)
		{
			ReadFormatHeader();
			ReadVersionProperties(solution);
			
			// Read solution folder and project entries:
			var solutionEntries = new List<ProjectLoadInformation>();
			var projectInfoDict = new Dictionary<Guid, ProjectLoadInformation>();
			var solutionFolderDict = new Dictionary<Guid, SolutionFolder>();
			int projectCount = 0;
			bool fixedGuidConflicts = false;
			
			ProjectLoadInformation information;
			while ((information = ReadProjectEntry(solution)) != null) {
				solutionEntries.Add(information);
				if (projectInfoDict.ContainsKey(information.IdGuid)) {
					// resolve GUID conflicts
					information.IdGuid = Guid.NewGuid();
					fixedGuidConflicts = true;
				}
				projectInfoDict.Add(information.IdGuid, information);
				
				if (information.TypeGuid == ProjectTypeGuids.SolutionFolder) {
					solutionFolderDict.Add(information.IdGuid, CreateSolutionFolder(solution, information));
				} else {
					projectCount++;
				}
			}
			
			progress.CancellationToken.ThrowIfCancellationRequested();
			
			// Read global sections:
			if (currentLine != "Global") {
				if (currentLine == null)
					throw Error("Unexpected end of file");
				else
					throw Error("Unknown line: " + currentLine);
			}
			NextLine();
			
			Dictionary<Guid, SolutionFolder> guidToParentFolderDict = null;
			
			SolutionSection section;
			while ((section = ReadSection(isGlobal: true)) != null) {
				switch (section.SectionName) {
					case "SolutionConfigurationPlatforms":
						var configurations = LoadSolutionConfigurations(section);
						foreach (var config in configurations.Select(c => c.Configuration).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
							solution.ConfigurationNames.Add(config, null);
						foreach (var platform in configurations.Select(c => c.Platform).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
							solution.PlatformNames.Add(platform, null);
						break;
					case "ProjectConfigurationPlatforms":
						LoadProjectConfigurations(section, projectInfoDict);
						break;
					case "NestedProjects":
						guidToParentFolderDict = LoadNesting(section, solutionFolderDict);
						break;
					default:
						solution.GlobalSections.Add(section);
						break;
				}
			}
			if (currentLine != "EndGlobal")
				throw Error("Expected 'EndGlobal'");
			NextLine();
			if (currentLine != null)
				throw Error("Expected end of file");
			
			solution.LoadPreferences();
			
			// Now that the project configurations have been set, we can actually load the projects:
			int projectsLoaded = 0;
			foreach (var projectInfo in solutionEntries) {
				ISolutionItem solutionItem;
				if (projectInfo.TypeGuid == ProjectTypeGuids.SolutionFolder) {
					solutionItem = solutionFolderDict[projectInfo.IdGuid];
				} else {
					// Load project:
					projectInfo.ActiveProjectConfiguration = projectInfo.ConfigurationMapping.GetProjectConfiguration(solution.ActiveConfiguration);
					progress.TaskName = "Loading " + projectInfo.ProjectName;
					using (projectInfo.ProgressMonitor = progress.CreateSubTask(1.0 / projectCount)) {
						solutionItem = ProjectBindingService.LoadProject(projectInfo);
					}
					projectsLoaded++;
					progress.Progress = (double)projectsLoaded / projectCount;
				}
				// Add solutionItem to solution:
				SolutionFolder folder;
				if (guidToParentFolderDict != null && guidToParentFolderDict.TryGetValue(projectInfo.IdGuid, out folder)) {
					folder.Items.Add(solutionItem);
				} else {
					solution.Items.Add(solutionItem);
				}
			}
			
			solution.IsDirty = fixedGuidConflicts; // reset IsDirty=false unless we've fixed GUID conflicts
		}