Пример #1
0
        public override void Update(string file)
        {
            var document      = DocumentHelper.GetXDocument(file);
            var directoryName = Path.GetDirectoryName(file) + "";

            if (IsApplicationProject(document))
            {
                AddRequiredReferences(document, file);
            }
            UpdateReferences(document, directoryName, file);
            UpdateConfig(file);
            if (SyncConfigurations(document))
            {
                DocumentHelper.Save(document, file);
            }

            var licElement = document.Descendants().FirstOrDefault(element => element.Name.LocalName == "EmbeddedResource" && element.Attribute("Include").Value == @"Properties\licenses.licx");

            if (licElement != null)
            {
                licElement.Remove();
                DocumentHelper.Save(document, file);
            }
            var combine = Path.Combine(Path.GetDirectoryName(file) + "", @"Properties\licenses.licx");

            if (File.Exists(combine))
            {
                File.Delete(combine);
            }

            UpdateVs2010Compatibility(document, file);
        }
Пример #2
0
        void UpdateReferences(XDocument document, string directoryName, string file)
        {
            var references = document.Descendants().Where(IsXpandOrDXElement);

            foreach (XElement reference in references)
            {
                var attribute = reference.Attribute("Include");

                var value = Regex.Match(attribute.Value, "(Xpand.[^,]*)|(DevExpress.[^,]*)", RegexOptions.Singleline | RegexOptions.IgnoreCase).Value;
                if (string.CompareOrdinal(attribute.Value, value) != 0)
                {
                    attribute.Value = value;
                    DocumentHelper.Save(document, file);
                }

                UpdateElementValue(reference, "SpecificVersion", "False", file, document);

                if (_copyLocalReferences.Any(s => attribute.Value.StartsWith(s)))
                {
                    UpdateElementValue(reference, "Private", "True", file, document);
                }

                if (reference.Attribute("Include").Value.StartsWith("Xpand."))
                {
                    var path = CalcPathToXpandDll(directoryName) + attribute.Value + ".dll";
                    UpdateElementValue(reference, "HintPath", path, file, document);
                }
            }
        }
Пример #3
0
        void UpdateElementValue(XElement reference, string name, string value, string file, XDocument document)
        {
            var element = reference.Nodes().OfType <XElement>().FirstOrDefault(xelement => xelement.Name.LocalName == name);

            if (element == null)
            {
                element = new XElement(_xNamespace + name);
                reference.Add(element);
                element.Value = value;
                DocumentHelper.Save(document, file);
            }
            else if (string.CompareOrdinal(value, element.Value) != 0)
            {
                element.Value = value;
                DocumentHelper.Save(document, file);
            }
        }
Пример #4
0
        void AddRequiredReferences(XDocument document, string file)
        {
            var referencesItemGroup = document.Descendants().First(element => element.Name.LocalName == "Reference").Parent;

            if (referencesItemGroup == null)
            {
                throw new NullReferenceException("referencesItemGroup");
            }

            foreach (string reference in RequiredReferencesThatDoNotExist(document))
            {
                var referenceElement = new XElement(_xNamespace + "Reference");
                referenceElement.Add(new XAttribute("Include", reference));
                referencesItemGroup.Add(referenceElement);
                DocumentHelper.Save(document, file);
            }
        }
Пример #5
0
        public override void Update(string file)
        {
            var document       = DocumentHelper.GetXDocument(file);
            var versionElement = document.Descendants().First(element => element.Name.LocalName == "version");

            versionElement.Value = _version;
            var dependenciesElement = document.Descendants().FirstOrDefault(element => element.Name.LocalName.ToLower() == "dependencies");

            if (dependenciesElement != null)
            {
                foreach (var element in dependenciesElement.Elements())
                {
                    element.SetAttributeValue("version", _version);
                }
            }
            DocumentHelper.Save(document, file);
        }
Пример #6
0
        void UpdateVs2010Compatibility(XDocument document, string file)
        {
            var elements = document.Descendants().Where(element
                                                        => element.Name.LocalName == "VSToolsPath" || element.Name.LocalName == "VisualStudioVersion");
            var  xElements = elements as XElement[] ?? elements.ToArray();
            bool save      = xElements.Any();

            xElements.Remove();


            elements = document.Descendants().Where(element
                                                    => element.Name.LocalName == "Import" &&
                                                    (element.Attribute("Project").Value.StartsWith("$(MSBuildExtensionsPath)") ||
                                                     element.Attribute("Project").Value.StartsWith("$(MSBuildExtensionsPath32)")));
            var enumerable = elements as XElement[] ?? elements.ToArray();

            if (!save)
            {
                save = enumerable.Any();
            }

            if (IsWeb(document, GetOutputType(document)) && !document.Descendants().Any(element =>
                                                                                        element.Name.LocalName == "Import" && element.Attribute("Project").Value.StartsWith("$(VSToolsPath)") &&
                                                                                        element.Attribute("Condition").Value.StartsWith("'$(VSToolsPath)' != ''")))
            {
                var element = new XElement(_xNamespace + "Import");
                element.SetAttributeValue("Project", @"$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets");
                element.SetAttributeValue("Condition", @"'$(VSToolsPath)' != ''");
                Debug.Assert(document.Root != null, "document.Root != null");
                document.Root.Add(element);
                save = true;
            }

            enumerable.Remove();

            if (save)
            {
                DocumentHelper.Save(document, file);
            }
        }