private static void DeserializeProject(TextReader reader, ref string currentLine, SolutionFile solutionFile) { if (!SolutionFileTextSerializer.ProjectLineRegex.IsMatch(currentLine)) { throw new Exception($"Unknown line.\nExpected: \"Project...\".\nFound: {currentLine}"); } var matches = Regex.Matches(currentLine, SolutionFileTextSerializer.ProjectLineValuesRegexPattern); var projectTypeGUIDStr = matches[0].Value.Trim('"'); var projectName = matches[1].Value.Trim('"'); var projectFileRelativePathValue = matches[2].Value.Trim('"'); var projectGUIDStr = matches[3].Value.Trim('"'); var projectTypeGUID = Guid.Parse(projectTypeGUIDStr); var projectGUID = Guid.Parse(projectGUIDStr); var solutionProjectFileReference = new SolutionFileProjectReference { ProjectTypeGUID = projectTypeGUID, ProjectName = projectName, ProjectFileRelativePathValue = projectFileRelativePathValue, ProjectGUID = projectGUID }; solutionFile.SolutionFileProjectReferences.Add(solutionProjectFileReference); currentLine = reader.ReadLine(); if (!SolutionFileTextSerializer.ProjectLineEndRegex.IsMatch(currentLine)) { throw new Exception($"Unknown line.\nExpected: \"EndProject\".\nFound: {currentLine}"); } }
private void AddProjectReference(SolutionFile solutionFile, SolutionFileProjectReference solutionFileProjectReference) { solutionFile.SolutionFileProjectReferences.Add(solutionFileProjectReference); // Acquire SolutionConfigurationPlatforms global section, adding all default SolutionBuildConfigurationPlatforms if need be. var solutionConfigurationPlatforms = solutionFile.GlobalSections.AcquireSolutionConfigurationPlatformsGlobalSection(SolutionConfigurationPlatformsGlobalSection.NewAddDefaultSolutionBuildConfigurationPlatforms); var projectConfigurationPlatforms = solutionFile.GlobalSections.AcquireProjectConfigurationPlatformsGlobalSection(); projectConfigurationPlatforms.AddProjectConfigurations(solutionFileProjectReference.ProjectGUID, solutionConfigurationPlatforms); }
private SolutionFileProjectReference CreateNewSolutionFolder(string solutionFolderName) { var solutionFolderProject = new SolutionFileProjectReference() { ProjectTypeGUID = this.VisualStudioSolutionFolderProjectTypeGuidProvider.GetVisualStudioSolutionFolderProjectTypeGuid(), ProjectGUID = this.VisualStudioNewProjectGuidProvider.GetNewVisualStudioProjectGuid(), ProjectName = solutionFolderName, ProjectFileRelativePathValue = solutionFolderName, }; return(solutionFolderProject); }
public void AddProjectFile(SolutionFile solutionFile, string solutionFilePath, string projectFilePath, Guid projectTypeGuid, Guid projectGuid) { // Special non-relative formatting. var projectFileRelativePath = this.StringlyTypedPathOperator.GetSolutionFileProjectFileRelativePath(solutionFilePath, projectFilePath); // Get project name from project file path. var projectFileName = this.StringlyTypedPathOperator.GetFileName(projectFilePath); var projectName = this.VisualStudioProjectFileNameConventions.GetProjectName(projectFileName); var solutionFileProjectReference = SolutionFileProjectReference.New(projectName, projectFileRelativePath, projectTypeGuid, projectGuid); this.AddProjectReference(solutionFile, solutionFileProjectReference); }
private bool RemoveProjectReference(SolutionFile solutionFile, SolutionFileProjectReference projectReference) { // Is the project reference in a nested solution folder? var hasNestedProjectsGlobalSection = solutionFile.GlobalSections.HasNestedProjectsGlobalSection(out var nestedProjectsGlobalSection); if (hasNestedProjectsGlobalSection) { nestedProjectsGlobalSection.ProjectNestings.RemoveAll(x => x.ChildProjectGUID == projectReference.ProjectGUID); } // Remove the project configuration platform entries. var hasProjectConfigurationPlatformsGlobalSection = solutionFile.GlobalSections.HasProjectConfigurationPlatformsGlobalSection(out var projectConfigurationPlatformsGlobalSection); if (hasProjectConfigurationPlatformsGlobalSection) { projectConfigurationPlatformsGlobalSection.ProjectBuildConfigurationMappings.RemoveAll(x => x.ProjectGUID == projectReference.ProjectGUID); } solutionFile.SolutionFileProjectReferences.Remove(projectReference); return(true); }
public static bool SolutionFolderContainsChildSolutionFolder(this IVisualStudioSolutionFileOperator visualStudioSolutionFileOperator, SolutionFile solutionFile, string parentSolutionFolderPath, string childSolutionFolderName, out SolutionFileProjectReference childSolutionFolder) { var childSolutionFolders = visualStudioSolutionFileOperator.ListSolutionFolderSolutionFolders(solutionFile, parentSolutionFolderPath); childSolutionFolder = childSolutionFolders.Where(x => x.ProjectName == childSolutionFolderName).SingleOrDefault(); var childSolutionFolderExists = childSolutionFolder != default; return(childSolutionFolderExists); }
public bool HasSolutionFolder(SolutionFile solutionFile, string solutionFolderPath, out SolutionFileProjectReference solutionFolder) { var solutionFolderPathParts = this.SolutionFolderPathOperator.GetSolutionFolderPathParts(solutionFolderPath); VisualStudioSolutionFileOperator.VerifyNonEmptySolutionFolderPath(solutionFolderPathParts); var rootSolutionFolderName = solutionFolderPathParts.First(); var hasRootSolutionFolder = this.HasRootSolutionFolderProject(solutionFile, rootSolutionFolderName, out var rootSolutionFolder); if (!hasRootSolutionFolder) { solutionFolder = default; return(false); } var solutionFolderPathPartCount = solutionFolderPathParts.Count(); if (solutionFolderPathPartCount < 2) { // There is only a root. solutionFolder = rootSolutionFolder; return(hasRootSolutionFolder); } // Recurse down the solution folders. var currentSolutionFolderProject = rootSolutionFolder; foreach (var solutionFolderName in solutionFolderPathParts.Skip(1)) // Skip the root. { var hasChildSolutionFolder = this.HasChildSolutionFolderProject(solutionFile, solutionFolderName, currentSolutionFolderProject, out currentSolutionFolderProject); if (!hasChildSolutionFolder) { solutionFolder = default; return(false); } } solutionFolder = currentSolutionFolderProject; return(true); }
private static bool HasSolutionFolderProject(SolutionFile solutionFile, string solutionFolderName, IEnumerable <Guid> solutionFolderGUIDs, out SolutionFileProjectReference solutionFolderProject) { solutionFolderProject = solutionFile.SolutionFileProjectReferences.Where(x => solutionFolderGUIDs.Contains(x.ProjectGUID) && x.ProjectName == solutionFolderName).SingleOrDefault(); var solutionFolderExists = solutionFolderProject != default; return(solutionFolderExists); }
private bool HasChildSolutionFolderProject(SolutionFile solutionFile, string solutionFolderName, SolutionFileProjectReference parentSolutionFolderProject, out SolutionFileProjectReference solutionFolderProject) { var nestedProjectsGlobalSection = solutionFile.GlobalSections.AcquireNestedProjectsGlobalSection(); var childSolutionFolderGUIDs = VisualStudioSolutionFileOperator.GetChildSolutionFolderGUIDs(nestedProjectsGlobalSection, parentSolutionFolderProject.ProjectGUID); solutionFolderProject = solutionFile.SolutionFileProjectReferences.Where(x => x.ProjectName == solutionFolderName && childSolutionFolderGUIDs.Contains(x.ProjectGUID)).SingleOrDefault(); var hasChildSolutionFolderProject = solutionFolderProject != default; return(hasChildSolutionFolderProject); }
private SolutionFileProjectReference AcquireAndAddChildSolutionFolderProject(SolutionFile solutionFile, string solutionFolderName, SolutionFileProjectReference parentSolutionFolderProject) { var solutionFolderExists = this.HasChildSolutionFolderProject(solutionFile, solutionFolderName, parentSolutionFolderProject, out var solutionFolderProject); if (!solutionFolderExists) { // Solution folder does NOT exist. Create it. solutionFolderProject = this.CreateNewSolutionFolder(solutionFolderName); // Add the project reference. solutionFile.SolutionFileProjectReferences.Add(solutionFolderProject); // But also add a nested project. var solutionFolderNesting = new ProjectNesting() { ChildProjectGUID = solutionFolderProject.ProjectGUID, ParentProjectGUID = parentSolutionFolderProject.ProjectGUID, }; var nestedProjectsGlobalSection = solutionFile.GlobalSections.AcquireNestedProjectsGlobalSection(); nestedProjectsGlobalSection.ProjectNestings.Add(solutionFolderNesting); } return(solutionFolderProject); }
private bool HasRootSolutionFolderProject(SolutionFile solutionFile, string solutionFolderName, out SolutionFileProjectReference rootSolutionFolder) { var rootSolutionFolderProjects = this.GetRootSolutionFolderProjects(solutionFile); rootSolutionFolder = rootSolutionFolderProjects.Where(x => x.ProjectName == solutionFolderName).SingleOrDefault(); var rootSolutionFolderExists = rootSolutionFolder != default; return(rootSolutionFolderExists); }
private bool HasProjectReference(SolutionFile solutionFile, string solutionFilePath, string projectFilePath, out SolutionFileProjectReference projectReference) { var projectFileRelativePath = this.StringlyTypedPathOperator.GetSolutionFileProjectFileRelativePath(solutionFilePath, projectFilePath); projectReference = solutionFile.SolutionFileProjectReferences.Where(x => x.ProjectFileRelativePathValue == projectFileRelativePath).SingleOrDefault(); var hasProjectFile = projectReference != default; return(hasProjectFile); }