1 // Copyright (c) Microsoft. All rights reserved. 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 4 using System; 5 using System.Collections.Generic; 6 using System.Text; 7 using System.Xml; 8 9 namespace Microsoft.Build.BuildEngine 10 { 11 static internal class VCProjectParser 12 { 13 /// <summary> 14 /// For a given VC project, retrieves the projects it references 15 /// </summary> 16 /// <param name="projectPath"></param> 17 /// <returns></returns> 18 /// <owner>LukaszG</owner> GetReferencedProjectGuids(XmlDocument project)19 static internal List<string> GetReferencedProjectGuids(XmlDocument project) 20 { 21 List<string> referencedProjectGuids = new List<string>(); 22 23 XmlNodeList referenceElements = project.DocumentElement.GetElementsByTagName("References"); 24 25 if (referenceElements.Count > 0) 26 { 27 foreach (XmlElement referenceElement in ((XmlElement)referenceElements[0]).GetElementsByTagName("ProjectReference")) 28 { 29 string referencedProjectGuid = referenceElement.GetAttribute("ReferencedProjectIdentifier"); 30 31 if (!string.IsNullOrEmpty(referencedProjectGuid)) 32 { 33 referencedProjectGuids.Add(referencedProjectGuid); 34 } 35 } 36 } 37 38 return referencedProjectGuids; 39 } 40 41 /// <summary> 42 /// Is the project built as a static library for the given configuration? 43 /// </summary> IsStaticLibrary(XmlDocument project, string configurationName)44 internal static bool IsStaticLibrary(XmlDocument project, string configurationName) 45 { 46 XmlNodeList configurationsElements = project.DocumentElement.GetElementsByTagName("Configurations"); 47 XmlElement configurationElement = null; 48 49 bool isStaticLibrary = false; 50 51 // There should be only one configurations element 52 if (configurationsElements.Count > 0) 53 { 54 foreach (XmlNode configurationNode in configurationsElements[0].ChildNodes) 55 { 56 if (configurationNode.NodeType == XmlNodeType.Element) 57 { 58 XmlElement element = (XmlElement)configurationNode; 59 60 // Look for configuration that matches our name 61 if ((string.Compare(element.Name, "Configuration", StringComparison.OrdinalIgnoreCase) == 0) && 62 (string.Compare(element.GetAttribute("Name"), configurationName, StringComparison.OrdinalIgnoreCase) == 0)) 63 { 64 configurationElement = element; 65 66 string configurationType = configurationElement.GetAttribute("ConfigurationType"); 67 isStaticLibrary = (configurationType == "4"); 68 69 // we found our configuration, nothing more to do here 70 break; 71 } 72 } 73 } 74 } 75 76 return isStaticLibrary; 77 } 78 } 79 } 80