public static void SyncProjectReferences(this IOutputTarget _project, XDocument doc)
        {
            if (_project.Dependencies().Count <= 0)
            {
                return;
            }

            var itemGroupElement = doc.XPathSelectElement("Project/ItemGroup[ProjectReference]");

            if (itemGroupElement == null)
            {
                itemGroupElement = new XElement("ItemGroup");
                itemGroupElement.Add(Environment.NewLine);
                itemGroupElement.Add("  ");

                var projectElement = doc.XPathSelectElement("Project");

                projectElement.Add("  ");
                projectElement.Add(itemGroupElement);
                projectElement.Add(Environment.NewLine);
                projectElement.Add("  ");
            }

            foreach (var dependency in _project.Dependencies())
            {
                var projectUrl           = string.Format("..\\{0}\\{0}.csproj", dependency.Name);
                var projectReferenceItem = doc.XPathSelectElement($"/Project/ItemGroup/ProjectReference[@Include='{projectUrl}']");
                if (projectReferenceItem != null)
                {
                    continue;
                }

                /*
                 * <ProjectReference Include="..\Intent.SoftwareFactory\Intent.SoftwareFactory.csproj"/>
                 */

                var item = new XElement(XName.Get("ProjectReference"));
                item.Add(new XAttribute("Include", projectUrl));

                itemGroupElement.Add("  ");
                itemGroupElement.Add(item);
                itemGroupElement.Add(Environment.NewLine);
                itemGroupElement.Add("  ");
            }
        }
Ejemplo n.º 2
0
        private void SyncProjectReferences()
        {
            if (_project.Dependencies().Count <= 0)
            {
                return;
            }

            var itemGroupElement = FindOrCreateProjectReferenceItemGroup();

            foreach (var dependency in _project.Dependencies())
            {
                var projectUrl           = string.Format("..\\{0}\\{0}.csproj", dependency.Name);
                var projectReferenceItem = _doc.XPathSelectElement($"/ns:Project/ns:ItemGroup/ns:ProjectReference[@Include='{projectUrl}']", _namespaces);
                if (projectReferenceItem != null)
                {
                    continue;
                }

                /*
                 * <ProjectReference Include="..\Intent.SoftwareFactory\Intent.SoftwareFactory.csproj"/>
                 */

                var item = new XElement(XName.Get("ProjectReference", _namespace.NamespaceName));
                item.Add(new XAttribute("Include", projectUrl));

                var projectIdElement = new XElement(XName.Get("Project", _namespace.NamespaceName))
                {
                    Value = $"{{{dependency.Id}}}"
                };
                item.Add(projectIdElement);

                var projectNameElement = new XElement(XName.Get("Name", _namespace.NamespaceName))
                {
                    Value = $"{dependency.Name}"
                };
                item.Add(projectNameElement);

                itemGroupElement.Add(item);
            }
        }
        public static void AddDependency(this IOutputTarget outputTarget, IOutputTarget dependency)
        {
            if (outputTarget.Equals(dependency))
            {
                throw new Exception($"OutputTarget [{outputTarget}] cannot add a dependency to itself");
            }
            var collection = outputTarget.Dependencies();

            if (!collection.Contains(dependency))
            {
                collection.Add(dependency);
            }
        }