//reads all the packages.config files provided as input
        //and returns a map which contains every package mapped to list of project locations in which it is referenced.
        public Dictionary <PackageElement, List <string> > readConfig(List <string> packageFilePaths, string root)//string path)
        {
            Dictionary <PackageElement, List <string> > map = new Dictionary <PackageElement, List <string> >();
            string fileName;

            Console.WriteLine("In read config");
            foreach (string path in packageFilePaths)
            {
                //Ignore packages.config files in these folders
                if (path.Contains(@"\.nuget") || path.Contains(@"\packages") || path.Contains(@"\Samples\"))
                {
                    continue;
                }
                fileName = path + "packages.config";
                var file = new PackageReferenceFile(fileName);

                string path1 = path.Replace(root, "");
                Console.WriteLine(path1);
                foreach (PackageReference packageReference in file.GetPackageReferences())
                {
                    PackageElement pe = new PackageElement(packageReference.Id, packageReference.Version);
                    if (!map.ContainsKey(pe))
                    {
                        //Console.WriteLine("add to map: "+packageReference.Id);
                        List <string> ans = new List <string>();
                        ans.Add(path1);
                        map.Add(pe, ans);
                    }
                    else
                    {
                        List <string> ans = map[pe];
                        ans.Add(path1);
                        map[pe] = ans;
                        //Console.WriteLine(" contains key "+ packageReference .Id+" "+ ans.Count);
                    }
                    Console.WriteLine("PackageId={0}, Version={1}", packageReference.Id, packageReference.Version);
                }
            }

            return(map);
        }
        //string path)
        //reads all the packages.config files provided as input
        //and returns a map which contains every package mapped to list of project locations in which it is referenced.
        public Dictionary<PackageElement, List<string>> readConfig(List<string> packageFilePaths, string root)
        {
            Dictionary<PackageElement, List<string>> map = new Dictionary<PackageElement, List<string>>();
            string fileName;
            Console.WriteLine("In read config");
            foreach (string path in packageFilePaths)
            {
                //Ignore packages.config files in these folders
                if (path.Contains(@"\.nuget") || path.Contains(@"\packages") || path.Contains(@"\Samples\"))
                    continue;
                fileName = path + "packages.config";
                var file = new PackageReferenceFile(fileName);

                string path1 = path.Replace(root, "");
                Console.WriteLine(path1);
                foreach (PackageReference packageReference in file.GetPackageReferences())
                {
                    PackageElement pe = new PackageElement(packageReference.Id, packageReference.Version);
                    if (!map.ContainsKey(pe))
                    {
                        //Console.WriteLine("add to map: "+packageReference.Id);
                        List<string> ans = new List<string>();
                        ans.Add(path1);
                        map.Add(pe, ans);
                    }
                    else
                    {
                        List<string> ans= map[pe];
                        ans.Add(path1);
                        map[pe] = ans;
                        //Console.WriteLine(" contains key "+ packageReference .Id+" "+ ans.Count);
                    }
                    Console.WriteLine("PackageId={0}, Version={1}", packageReference.Id, packageReference.Version);
                }
            }

            return map;
        }
Example #3
0
        //Package elements are considered as equal if they have same package names. Versions can be different.
        public override bool Equals(object obj)
        {
            PackageElement item = obj as PackageElement;

            return(item.Packageid == this.Packageid); // && item.Version == this.Version);
        }