コード例 #1
0
        public static void AddPackageReference(this XDocument document, string packageId, string version)
        {
            XElement existingPackageReference = document.Descendants()?.FirstOrDefault(
                item =>
                PackageReferenceElementName.Equals(item.Name?.LocalName, StringComparison.Ordinal) &&
                item.Attribute(PackageReferenceIncludeElementName)?.Value == packageId);

            if (existingPackageReference != null)
            {
                // If the package with the same version is already present, move on...
                if (existingPackageReference.Attribute(PackageReferenceVersionElementName)?.Value == version)
                {
                    return;
                }

                existingPackageReference.Remove();
            }

            XElement group   = document.GetUniformItemGroupOrNew(PackageReferenceElementName);
            XElement element = new XElement(PackageReferenceElementName,
                                            new XAttribute(PackageReferenceIncludeElementName, packageId),
                                            new XAttribute(PackageReferenceVersionElementName, version));

            group.Add(element);
        }
コード例 #2
0
        public static void RemovePackageReference(this XDocument document, string packageId)
        {
            XElement existingPackageReference = document.Descendants()?.FirstOrDefault(
                item =>
                PackageReferenceElementName.Equals(item.Name?.LocalName, StringComparison.Ordinal) &&
                item.Attribute(PackageReferenceIncludeElementName)?.Value == packageId);

            if (existingPackageReference != null)
            {
                existingPackageReference.Remove();
            }
        }
コード例 #3
0
        public async Task <IEnumerable <ExtensionPackageReference> > GetExtensions()
        {
            var project = await GetOrCreateProjectAsync(ProjectPath);

            return(project.Items
                   .Where(i => PackageReferenceElementName.Equals(i.ItemType, StringComparison.Ordinal) && !ExtensionsPackageId.Equals(i.Include, StringComparison.Ordinal))
                   .Select(i => new ExtensionPackageReference
            {
                Id = i.Include,
                Version = i.Metadata.FirstOrDefault(m => PackageReferenceVersionElementName.Equals(m.Name, StringComparison.Ordinal))?.Value
            })
                   .ToList());
        }
コード例 #4
0
        private static IList <LibraryRange> GetProjectDependencies(string projectFilePath)
        {
            using (var reader = XmlTextReader.Create(new StringReader(File.ReadAllText(projectFilePath))))
            {
                var root = ProjectRootElement.Create(reader);

                return(root.Items
                       .Where(i => PackageReferenceElementName.Equals(i.ItemType, StringComparison.Ordinal))
                       .Select(i => new LibraryRange
                {
                    Name = i.Include,
                    VersionRange = VersionRange.Parse(i.Metadata.First(m => PackageReferenceVersionElementName.Equals(m.Name, StringComparison.Ordinal)).Value)
                })
                       .ToList());
            }
        }
コード例 #5
0
        private static IList <LibraryRange> GetProjectDependencies(string projectFilePath)
        {
            using (var reader = XmlTextReader.Create(new StringReader(File.ReadAllText(projectFilePath))))
            {
                XDocument root = XDocument.Load(reader);

                return(root.Descendants()?
                       .Where(i => PackageReferenceElementName.Equals(i.Name.LocalName, StringComparison.Ordinal))
                       .Select(i => new LibraryRange
                {
                    Name = i.Attribute(PackageReferenceIncludeElementName)?.Value,
                    VersionRange = VersionRange.Parse(i.Attribute(PackageReferenceVersionElementName)?.Value)
                })
                       .ToList());
            }
        }
コード例 #6
0
        public async Task <IEnumerable <ExtensionPackageReference> > GetExtensions()
        {
            string extensionsProjectPath = _extensionBundleManager.IsExtensionBundleConfigured() ? await GetBundleProjectPath() : DefaultExtensionsProjectPath;

            if (string.IsNullOrEmpty(extensionsProjectPath))
            {
                return(Enumerable.Empty <ExtensionPackageReference>());
            }

            var project = await GetOrCreateProjectAsync(extensionsProjectPath);

            return(project.Items
                   .Where(i => PackageReferenceElementName.Equals(i.ItemType, StringComparison.Ordinal) && !MetadataGeneratorPackageId.Equals(i.Include, StringComparison.Ordinal))
                   .Select(i => new ExtensionPackageReference
            {
                Id = i.Include,
                Version = i.Metadata.FirstOrDefault(m => PackageReferenceVersionElementName.Equals(m.Name, StringComparison.Ordinal))?.Value
            })
                   .ToList());
        }