public static SolutionProjectReference TryParse(IFileSystem fileSystem, string[] lines, ref int index) { var match = _projectRegex.Match(lines[index]); if (match.Success == false) { return(null); } var project = new SolutionProjectReference { Name = match.Groups["name"].Value, Path = match.Groups["path"].Value, Type = new Guid(match.Groups["projectTypeGuid"].Value), Guid = new Guid(match.Groups["projectGuid"].Value), File = fileSystem.GetFile(match.Groups["path"].Value) }; for (index++; index < lines.Length; index++) { if (lines[index] == "EndProject") { break; } project._lines.Add(lines[index]); } return(project); }
void ParseContent() { var lines = _file.ReadString().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { _content.Add( SolutionFormatVersion.TryParse(lines, ref i) ?? SolutionVisualStudioVersion.TryParse(lines, ref i) ?? SolutionProjectReference.TryParse(_file.FileSystem, lines, ref i) ?? Global.TryParse(lines, ref i) ?? (object)lines[i] ); } }
public SolutionProjectReferences CreateFromSolutionFile(string solutionFilePath) { var entries = new List <SolutionProjectReference>(); _solutionProjectBlockHandler.Initialize(solutionFilePath); var projectReferences = _solutionFileService.ParseMicrosoftBuildProjects(solutionFilePath); foreach (var project in projectReferences) { var solutionProjectBlock = _solutionProjectBlockHandler.FindBlock(project.ProjectName); var entry = new SolutionProjectReference( solutionProjectBlock.Data, project.ProjectName, project.ProjectGuid, project.AbsolutePath); entries.Add(entry); } var result = new SolutionProjectReferences(entries); return(result); }
public IProject AddProject(IFile projectFile) { using (var projectStream = projectFile.OpenRead()) { var xmlDoc = XDocument.Load(new XmlTextReader(projectStream)); var projectGuid = (from propertyGroup in xmlDoc.Descendants(XName.Get("PropertyGroup", NS_MSBUILD)) from guid in propertyGroup.Descendants(XName.Get("ProjectGuid", NS_MSBUILD)) select guid.Value).First(); var projectTypeGuid = GetFromFileName(projectFile); var newProject = new SolutionProjectReference { Guid = new Guid(projectGuid), Name = projectFile.NameWithoutExtension, Path = projectFile.Path.MakeRelative(_file.Parent.Path), Type = projectTypeGuid }; var indexToInsert = _content.OfType <SolutionProjectReference>().Any() ? _content.IndexOf(_content.OfType <SolutionProjectReference>().Last()) + 1 : _content.Count; _content.Insert(indexToInsert, newProject); return(newProject); } }
public static SolutionProjectReference TryParse(IFileSystem fileSystem, string[] lines, ref int index) { var match = _projectRegex.Match(lines[index]); if (match.Success == false) return null; var project = new SolutionProjectReference { Name = match.Groups["name"].Value, Path = match.Groups["path"].Value, Type = new Guid(match.Groups["projectTypeGuid"].Value), Guid = new Guid(match.Groups["projectGuid"].Value), File = fileSystem.GetFile(match.Groups["path"].Value) }; for (index++; index < lines.Length; index++) { if (lines[index] == "EndProject") break; project._lines.Add(lines[index]); } return project; }
public IProject AddProject(IFile projectFile) { using (var projectStream = projectFile.OpenRead()) { var xmlDoc = XDocument.Load(new XmlTextReader(projectStream)); var projectGuid = (from propertyGroup in xmlDoc.Descendants(XName.Get("PropertyGroup", NS_MSBUILD)) from guid in propertyGroup.Descendants(XName.Get("ProjectGuid", NS_MSBUILD)) select guid.Value).First(); var projectTypeGuid = GetFromFileName(projectFile); var newProject = new SolutionProjectReference { Guid = new Guid(projectGuid), Name = projectFile.NameWithoutExtension, Path = projectFile.Path.MakeRelative(_file.Parent.Path), Type = projectTypeGuid }; var indexToInsert = _content.OfType<SolutionProjectReference>().Any() ? _content.IndexOf(_content.OfType<SolutionProjectReference>().Last()) + 1 : _content.Count; _content.Insert(indexToInsert, newProject); return newProject; } }