Пример #1
0
        public void UpdateInDoc(XDocument xdoc, XNamespace ns)
        {
            // Update existing ref (hint path)

            List <XElement> references2 =
                (from el in xdoc.Element(ns + "Project").Elements(ns + "ItemGroup").Elements(ns + "Reference")
                 where el.Attribute("Include") != null && Project.GetShortRef(el.Attribute("Include").Value) == Project.GetShortRef(Include)
                 select el)
                .ToList();

            if (references2.Count < 1)
            {
                ConsoleHelper.WriteLine($"  Error: Couldn't update assembly ref: '{Include}': Didn't find reference in project file.", false);
                return;
            }
            if (references2.Count > 1)
            {
                ConsoleHelper.WriteLine($"  Error: Couldn't update assembly ref: '{Include} ': Found too many matching references in project file.", false);
                return;
            }

            XElement reference = references2[0];


            XElement hintPath = reference.Element(ns + "HintPath");

            if (Hintpath == null)
            {
                if (hintPath != null)
                {
                    string oldpath = hintPath.Value;
                    if (oldpath != Hintpath)
                    {
                        ConsoleHelper.WriteLine($"  Updating assembly ref: Removing hintpath: '{Include}': '{oldpath}'.", true);
                        hintPath.Remove();
                    }
                }
            }
            else
            {
                if (hintPath == null)
                {
                    ConsoleHelper.WriteLine($"  Updating assembly ref: Adding hintpath: '{Include}', '{Hintpath}'.", true);
                    hintPath = new XElement(ns + "HintPath", Hintpath);
                    reference.Add(hintPath);
                }
                else
                {
                    string oldpath = hintPath.Value;
                    if (oldpath != Hintpath)
                    {
                        ConsoleHelper.WriteLine($"  Updating assembly ref: Updating hintpath: '{Include}': '{oldpath}' -> '{Hintpath}'.", true);
                        hintPath.Value = Hintpath;
                    }
                }
            }

            XAttribute includeattr = reference.Attribute("Include");

            if (includeattr.Value != Include)
            {
                ConsoleHelper.WriteLine($"  Updating assembly ref: Updating include: '{includeattr.Value}' -> '{Include}'.", true);
                includeattr.Value = Include;
            }
        }