private void ParseNetCore(VisualStudioSolutionProject visualStudioProject, XDocument xDocument) { string sdkValue = xDocument.Descendants("Project").Attributes("Sdk").Select(a => a.Value).FirstOrDefault(); visualStudioProject.Type = VsProjectType.NetCore; if (sdkValue == "Microsoft.NET.Sdk.Web") { visualStudioProject.Type |= VsProjectType.Web; return; } if (sdkValue == "Microsoft.NET.Sdk") { string outputType = xDocument.Descendants("OutputType").Select(a => a.Value).FirstOrDefault(); if (outputType != null && outputType.Equals("Exe", StringComparison.InvariantCultureIgnoreCase)) { visualStudioProject.Type |= VsProjectType.Console; } if (xDocument.Descendants("PackageReference").Any(d => d.Attribute("Include")?.Value == "MSTest.TestFramework")) { visualStudioProject.Type |= VsProjectType.Test; } if (xDocument.Descendants("PackageReference").Any(d => d.Attribute("Include")?.Value == "MSTest.TestFramework")) { visualStudioProject.Type |= VsProjectType.ClassLibrary; } } }
public IList <VisualStudioSolutionProject> Parse(string solutionFilePath) { string text = File.ReadAllText(solutionFilePath); string folder = Path.GetDirectoryName(solutionFilePath); IList <VisualStudioSolutionProject> result = new List <VisualStudioSolutionProject>(); Match match = projectParser.Match(text); while (match.Success) { if (match.Groups["type"].Value == "2150E333-8FDC-42A3-9474-1A3956D46DE8") // project group { match = match.NextMatch(); continue; } VisualStudioSolutionProject visualStudioProject = new VisualStudioSolutionProject() { Guid = Guid.Parse(match.Groups["guid"].Value), Name = match.Groups["name"].Value, ProjectFile = match.Groups["file"].Value, TypeGuid = Guid.Parse(match.Groups["type"].Value), }; string projectFile = Path.Combine(folder, visualStudioProject.ProjectFile); this.ProcessCSProjFile(projectFile, visualStudioProject); result.Add(visualStudioProject); match = match.NextMatch(); } return(result); }
private void DetermineProjectType(VisualStudioSolutionProject visualStudioProject, XDocument xDocument, XNamespace fileNamespace) { XElement projectTypeGuids = xDocument.Descendants(fileNamespace + "ProjectTypeGuids").FirstOrDefault(); if (projectTypeGuids != null) { Match match = guidParser.Match(projectTypeGuids.Value); while (match.Success) { visualStudioProject.Type |= this.GetTypeByGuid(match.Groups["guid"].Value); match = match.NextMatch(); } } string typeGuid = visualStudioProject.TypeGuid.ToString().ToUpper(); XElement outputTypeElement = xDocument.Descendants(fileNamespace + "OutputType").FirstOrDefault(); if (outputTypeElement != null && outputTypeElement.Value == "Exe") { visualStudioProject.Type |= VsProjectType.Console; } else if (outputTypeElement != null && outputTypeElement.Value == "WinExe") { visualStudioProject.Type |= VsProjectType.WindowsApplication; } else if (outputTypeElement != null && outputTypeElement.Value == "Database") { visualStudioProject.Type |= VsProjectType.Database; } else if (xDocument.Descendants(fileNamespace + "UseIISExpress").Any()) { visualStudioProject.Type |= VsProjectType.Web; switch (typeGuid.ToUpper()) { case "E3E379DF-F4C6-4180-9B81-6769533ABE47": visualStudioProject.MvcVersion = 4; break; case "E53F8FEA-EAE0-44A6-8774-FFD645390401": visualStudioProject.MvcVersion = 3; break; case "F85E285D-A4E0-4152-9332-AB1D724D3325": visualStudioProject.MvcVersion = 2; break; case "603C0E0B-DB56-11DC-BE95-000D561079B0": visualStudioProject.MvcVersion = 1; break; default: break; } } }
private void DetermineProjectCLR(VisualStudioSolutionProject visualStudioProject, XDocument xDocument, XNamespace fileNamespace) { visualStudioProject.TargetFrameworkVersion = xDocument.Descendants(fileNamespace + "TargetFrameworkVersion").Select(n => n.Value).FirstOrDefault(); visualStudioProject.ContentFiles = xDocument.Descendants(fileNamespace + "Content").Select(n => n.Attribute("Include").Value).ToList(); visualStudioProject.ReferenceLibraries = xDocument .Descendants(fileNamespace + "Content") .SelectMany(n => n.Descendants("HintPath")) .Select(n => n.Value) .ToList(); }
private void ProcessCSProjFile(string projectFile, VisualStudioSolutionProject visualStudioProject) { XDocument xDocument = XDocument.Load(projectFile); XNamespace fileNamespace = "http://schemas.microsoft.com/developer/msbuild/2003"; if (xDocument.Descendants("Project").Attributes("Sdk").Select(a => a.Value).FirstOrDefault() != null) { this.ParseNetCore(visualStudioProject, xDocument); } else { this.DetermineProjectType(visualStudioProject, xDocument, fileNamespace); this.DetermineProjectCLR(visualStudioProject, xDocument, fileNamespace); } }