private void FindProjectsClassic(XmlNode node)
        {
            XmlNode lstProjectNode = null;

            foreach (XmlNode aNode in node.ChildNodes)
            {
                lstProjectNode = FindParentNode(aNode, "ProjectReference");

                if (lstProjectNode != null)
                {
                    break;
                }
            }

            if (lstProjectNode != null)
            {
                foreach (XmlNode aProject in lstProjectNode.ChildNodes)
                {
                    var projectId   = aProject.ChildNodes[0].InnerText;
                    var projectName = aProject.ChildNodes[1].InnerText;

                    ProjectReferences.Add(new ProjectReference()
                    {
                        Type = ProjectType.Classic,
                        Id   = projectId,
                        Name = projectName,
                    });
                }
            }
        }
        private void FindProjectsSdk(XmlNode node)
        {
            XmlNode lstProjectNode = null;

            foreach (XmlNode aNode in node.ChildNodes)
            {
                lstProjectNode = FindParentNode(aNode, "ProjectReference");

                if (lstProjectNode != null)
                {
                    break;
                }
            }

            if (lstProjectNode != null)
            {
                foreach (XmlNode aProject in lstProjectNode.ChildNodes)
                {
                    var link = aProject.Attributes["Include"];

                    if (link != null)
                    {
                        var projLink = link.InnerText;

                        var basePath = System.IO.Path.GetDirectoryName(_path);

                        var projPath = Path.Combine(basePath, projLink);

                        var fileInfo = new FileInfo(projPath);

                        var path = fileInfo.FullName;

                        var name = Path.GetFileNameWithoutExtension(path);

                        ProjectReferences.Add(new ProjectReference()
                        {
                            Type     = ProjectType.SDK,
                            FullPath = path,
                            Name     = name,
                        });
                    }
                }
            }
        }
示例#3
0
        private void _parse()
        {
            ProjectName = Path.GetFileNameWithoutExtension(ProjectFilename);

            _xmlDocument = new XmlDocument();
            _xmlDocument.Load(ProjectFilename);
            var nsmgr = new XmlNamespaceManager(_xmlDocument.NameTable);

            nsmgr.AddNamespace("root", "http://schemas.microsoft.com/developer/msbuild/2003");
            _nsmgr = nsmgr;

            XmlElement root = _xmlDocument.DocumentElement;

            if (root == null)
            {
                throw new InvalidOperationException(string.Format("No document element: {0}", ProjectFilename));
            }

            XmlNode firstPropertyGroup = root.SelectSingleNode("//root:Project/root:PropertyGroup[not(@Condition)]",
                                                               nsmgr);

            if (firstPropertyGroup == null)
            {
                throw new InvalidOperationException(string.Format("No First PropertyGroup: {0}", ProjectFilename));
            }

            // Get ProjectGuid.
            XmlNode node = firstPropertyGroup.SelectSingleNode("root:ProjectGuid", nsmgr);

            ProjectGuid = Guid.Parse(node.InnerText);

            // Get Project general properties
            node = firstPropertyGroup.SelectSingleNode("root:Configuration", nsmgr);
            if (node != null)
            {
                Configuration = node.InnerText;
            }
            node = firstPropertyGroup.SelectSingleNode("root:Platform", nsmgr);
            if (node != null)
            {
                Platform = node.InnerText;
            }
            node = firstPropertyGroup.SelectSingleNode("root:OutputType", nsmgr);
            if (node != null)
            {
                OutputType = node.InnerText;
            }
            node = firstPropertyGroup.SelectSingleNode("root:RootNamespace", nsmgr);
            if (node != null)
            {
                RootNamespace = node.InnerText;
            }
            node = firstPropertyGroup.SelectSingleNode("root:AssemblyName", nsmgr);
            if (node != null)
            {
                AssemblyName = node.InnerText;
            }
            node = firstPropertyGroup.SelectSingleNode("root:TargetFrameworkVersion", nsmgr);
            if (node != null)
            {
                TargetFrameworkVersion = node.InnerText;
            }

            node = root.SelectSingleNode("//root:Project/root:PropertyGroup/root:PostBuildEvent", nsmgr);
            if (node != null)
            {
                if (!string.IsNullOrWhiteSpace(node.InnerText))
                {
                    PostBuildEvent = node.InnerText;
                }
            }
            node = root.SelectSingleNode("//root:Project/root:PropertyGroup/root:PreBuildEvent", nsmgr);
            if (node != null)
            {
                if (!string.IsNullOrWhiteSpace(node.InnerText))
                {
                    PreBuildEvent = node.InnerText;
                }
            }

            // Build configurations
            XmlNodeList nodes = root.SelectNodes("//root:Project/root:PropertyGroup[@Condition]", nsmgr);

            if (nodes != null)
            {
                //var sorter = new BuildConfigurationSorter();
                foreach (XmlNode node2 in nodes)
                {
                    BuildConfiguration configuration = BuildConfiguration.Parse(this, node2, nsmgr);
                    if (configuration != null)
                    {
                        _buildConfigurations.Add(configuration);
                    }
                }
            }

            // References
            nodes = root.SelectNodes("//root:Project/root:ItemGroup/root:Reference", nsmgr);
            Debug.Assert(nodes != null, "nodes != null");
            foreach (XmlNode node2 in nodes)
            {
                Reference reference = Reference.Parse(this, node2, nsmgr);
                if (reference != null)
                {
                    References.Add(reference);
                }
            }

            // Project References
            nodes = root.SelectNodes("//root:Project/root:ItemGroup/root:ProjectReference", nsmgr);
            Debug.Assert(nodes != null, "nodes != null");
            foreach (XmlNode node2 in nodes)
            {
                ProjectReference projectReference = ProjectReference.Parse(this, node2, nsmgr);
                if (projectReference != null)
                {
                    ProjectReferences.Add(projectReference);
                }
            }

            IsDirty = false;
        }
示例#4
0
 public Project WithProjectReference(ProjectReference projectReference)
 {
     ProjectReferences.Add(projectReference);
     return(this);
 }