Exemplo n.º 1
0
        // reads a project file and append PackageReference packages to the list
        private static void ReadCsProj(string filename, List <Package> packages)
        {
            //Console.WriteLine("read " + filename);

            CsProjProject proj;
            var           serializer = new XmlSerializer(typeof(CsProjProject));

            using (var reader = new IgnoreNsXmlTextReader(new StreamReader(filename)))
            {
                proj = (CsProjProject)serializer.Deserialize(reader);
            }

            foreach (var itemGroup in proj.ItemGroups)
            {
                if (itemGroup.Packages != null)
                {
                    foreach (var package in itemGroup.Packages)
                    {
                        var sversion = package.VersionE ?? package.VersionA;
                        if (!NuGetVersion.TryParse(sversion, out var version))
                        {
                            continue;
                        }
                        packages.Add(new Package {
                            Id = package.Id, Version = version, Project = GetDirectoryName(filename), Condition = itemGroup.Condition
                        });
                    }
                }
            }
        }
Exemplo n.º 2
0
        // reads a nuspec file and returns its dependencies
        // filename is the full or relative path to nuspec
        public Dependency[] GetNuSpecDependencies(string filename)
        {
            NuSpec nuspec;
            var    serializer = new XmlSerializer(typeof(NuSpec));

            using (var reader = new IgnoreNsXmlTextReader(new StreamReader(filename)))
            {
                nuspec = (NuSpec)serializer.Deserialize(reader);
            }
            var groups = nuspec.Metadata.Groups;

            var deps = new List <Dependency>();

            foreach (var group in groups)
            {
                var nudeps = group.Dependencies;

                foreach (var nudep in nudeps)
                {
                    var dep = new Dependency {
                        Id = nudep.Id
                    };

                    var parts = nudep.Version.Split(',');
                    if (parts.Length == 1)
                    {
                        dep.MinInclude = parts[0].StartsWith("[");
                        dep.MaxInclude = parts[0].EndsWith("]");

                        if (!NuGetVersion.TryParse(parts[0].Substring(1, parts[0].Length - 2).Trim(), out var version))
                        {
                            continue;
                        }
                        dep.MinVersion = dep.MaxVersion = version;
                    }
                    else
                    {
                        if (!NuGetVersion.TryParse(parts[0].Substring(1).Trim(), out var version))
                        {
                            continue;
                        }
                        dep.MinVersion = version;
                        if (!NuGetVersion.TryParse(parts[1].Substring(0, parts[1].Length - 1).Trim(), out version))
                        {
                            continue;
                        }
                        dep.MaxVersion = version;
                        dep.MinInclude = parts[0].StartsWith("[");
                        dep.MaxInclude = parts[1].EndsWith("]");
                    }

                    deps.Add(dep);
                }
            }

            return(deps.ToArray());
        }
Exemplo n.º 3
0
        // reads a package.config file and append packages to the list
        private static void ReadPackagesConfig(string filename, List <Package> packages)
        {
            //Console.WriteLine("read " + filename);

            PackagesConfigPackages pkgs;
            var serializer = new XmlSerializer(typeof(PackagesConfigPackages));

            using (var reader = new IgnoreNsXmlTextReader(new StreamReader(filename)))
            {
                pkgs = (PackagesConfigPackages)serializer.Deserialize(reader);
            }
            foreach (var p in pkgs.Packages)
            {
                if (!NuGetVersion.TryParse(p.Version, out var version))
                {
                    continue;
                }
                packages.Add(new Package {
                    Id = p.Id, Version = version, Project = GetDirectoryName(filename)
                });
            }
        }