public static MSBuildProject Load(XmlDocument xmlDocument) { if (xmlDocument == null) throw new ArgumentNullException("xmlDocument"); var nsManager = new XmlNamespaceManager(xmlDocument.NameTable); nsManager.AddNamespace("m", NamespaceUri); var project = new MSBuildProject(); foreach (XmlElement itemElement in xmlDocument.SelectNodes("//m:ItemGroup/*[@Include]", nsManager)) { if (itemElement.LocalName == "Reference") { var hintPath = (XmlElement)itemElement.SelectSingleNode("m:HintPath", nsManager); if (hintPath != null) project.references.Add(new ReferencedAssembly(itemElement.GetAttribute("Include"), hintPath.InnerText)); else project.references.Add(new ReferencedAssembly(itemElement.GetAttribute("Include"), null)); } else if (itemElement.LocalName == "ProjectReference") { var projectName = (XmlElement)itemElement.SelectSingleNode("m:Name", nsManager); if (projectName != null) project.referencedProjects.Add(new ReferencedProject(projectName.InnerText, itemElement.GetAttribute("Include"))); } else { project.projectFiles.Add(new ProjectFile(itemElement.GetAttribute("Include"), itemElement.LocalName)); } } foreach(XmlAttribute attribute in xmlDocument.SelectNodes("//m:Import/@Project", nsManager)) { if(attribute.Value != null && attribute.Value.IndexOf("WebApplication", StringComparison.OrdinalIgnoreCase) >= 0) { project.IsWebApplication = true; break; } } return project; }
private static IEnumerable<string> GetConfigFiles(MSBuildProject project) { return project.Files .Where(p => !string.Equals(p.Name, "packages.config", StringComparison.OrdinalIgnoreCase)) .Where(p => p.Name.EndsWith(".config", StringComparison.OrdinalIgnoreCase)) .Select(p => p.Name); }