private static string GenerateProjectInfoFromSolutionProject(SolutionProject solutionProject) { return(string.Format(ProjectInfoMask, solutionProject.ProjectTypeGuid.ToString().ToUpper(), solutionProject.ProjectGuid.ToString().ToUpper(), solutionProject.ProjectName, solutionProject.RelativePath)); }
/// <summary> /// Adds reference to a csproj file in a solution. /// </summary> /// <param name="slnFilePath">The solution file path</param> /// <param name="csProjFilePath">The csproj file path</param> /// <param name="projectGuid">The guid of the project</param> /// <param name="webAppName">The name of the SitefinityWebAWpp</param> public static void AddProject(string solutionFilePath, SolutionProject solutionProject) { string solutionFileContent = GetSolutionFileContentAsString(solutionFilePath); solutionFileContent = AddProjectInfoInSolutionFileContent(solutionFileContent, solutionProject); solutionFileContent = AddProjectGlobalSectionInSolutionFileContent(solutionFileContent, solutionProject); SaveSolutionFileContent(solutionFilePath, solutionFileContent); }
/// <summary> /// Returns the projects from a solution file. /// </summary> /// <param name="solutionFilePath">The path to the solution file.</param> /// <returns>Collection of <see cref="SolutionProject"/>.</returns> public static IEnumerable <SolutionProject> GetProjects(string solutionFilePath) { string solutionFileContent = GetSolutionFileContentAsString(solutionFilePath); IList <SolutionProject> solutionProjects = new List <SolutionProject>(); foreach (Match match in projectLineRegex.Matches(solutionFileContent)) { Guid projectTypeGuid = Guid.Parse(match.Groups[ProjectTypeGuidRegexGroupName].Value.Trim()); string projectName = match.Groups[ProjectNameRegexGroupName].Value.Trim(); string relativePath = match.Groups[ProjectRelativePathRegexGroupName].Value.Trim(); Guid projectGuid = Guid.Parse(match.Groups[ProjectGuidRegexGroupName].Value.Trim()); SolutionProject solutionProject = new SolutionProject(projectGuid, projectName, relativePath, projectTypeGuid, solutionFilePath); solutionProjects.Add(solutionProject); } return(solutionProjects); }
private static string AddProjectGlobalSectionInSolutionFileContent(string solutionFileContent, SolutionProject solutionProject) { int beginGlobalSectionIndex = solutionFileContent.IndexOf("GlobalSection(ProjectConfigurationPlatforms)"); int endGlobalSectionIndex = solutionFileContent.IndexOf("EndGlobalSection", beginGlobalSectionIndex); if (endGlobalSectionIndex < 0) { throw new Exception(Constants.SolutionNotReadable); } var globalSection = GenerateGlobalSectionFromSolutionProject(solutionProject); solutionFileContent = solutionFileContent.Insert(endGlobalSectionIndex, globalSection); return(solutionFileContent); }
private static string AddProjectInfoInSolutionFileContent(string solutionFileContent, SolutionProject solutionProject) { var endProjectIndex = solutionFileContent.LastIndexOf("EndProject"); if (endProjectIndex < 0) { throw new Exception(Constants.SolutionNotReadable); } var projectInfo = GenerateProjectInfoFromSolutionProject(solutionProject); solutionFileContent = solutionFileContent.Insert(endProjectIndex, projectInfo); return(solutionFileContent); }
private static string GenerateGlobalSectionFromSolutionProject(SolutionProject solutionProject) { return(string.Format(GlobalSectionMask, solutionProject.ProjectGuid.ToString().ToUpper())); }