<commit_before>namespace APIComparer.Backend
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using APIComparer.Shared;
    using NuGet;

    class NuGetDownloader
    {
        readonly string package;
        PackageManager packageManager;

        public NuGetDownloader(string nugetName, IEnumerable<string> repositories)
        {
            package = nugetName;

            //var nugetCacheDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet", "Cache");
            var nugetCacheDirectory = Path.Combine(AzureEnvironment.GetTempPath(), "packages");


            var reposToUse = new List<IPackageRepository>
            {
                PackageRepositoryFactory.Default.CreateRepository(nugetCacheDirectory)
            };

            reposToUse.AddRange(repositories.ToList().Select(r => PackageRepositoryFactory.Default.CreateRepository(r)));
            var repo = new AggregateRepository(reposToUse);

            packageManager = new PackageManager(repo, /*"packages"*/nugetCacheDirectory);
        }

        public List<string> DownloadAndExtractVersion(string version)
        {
            var semVer = SemanticVersion.Parse(version);

            packageManager.InstallPackage(package, semVer, true, false);

            var dirPath = Path.Combine(AzureEnvironment.GetTempPath(), "packages", string.Format("{0}.{1}", package, version), "lib");


            if (Directory.Exists(Path.Combine(dirPath, "net20")))
            {
                dirPath = Path.Combine(dirPath, "net20");
            }

            if (Directory.Exists(Path.Combine(dirPath, "net30")))
            {
                dirPath = Path.Combine(dirPath, "net30");
            }

            if (Directory.Exists(Path.Combine(dirPath, "net35")))
            {
                dirPath = Path.Combine(dirPath, "net35");
            }

            if (Directory.Exists(Path.Combine(dirPath, "net40")))
            {
                dirPath = Path.Combine(dirPath, "net40");
            }

            if (Directory.Exists(Path.Combine(dirPath, "net45")))
            {
                dirPath = Path.Combine(dirPath, "net45");
            }

            var files = Directory.EnumerateFiles(dirPath)
                .Where(f => f.EndsWith(".dll") || f.EndsWith(".exe"))
                .ToList();


            if (!files.Any())
            {
                throw new Exception("Couldn't find any assemblies in  " + dirPath);
            }

            return files;
        }
    }
}<commit_msg>Better handlig of netXX dirs in downloaded nugets<commit_after>namespace APIComparer.Backend
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using APIComparer.Shared;
    using NuGet;

    class NuGetDownloader
    {
        readonly string package;
        PackageManager packageManager;

        public NuGetDownloader(string nugetName, IEnumerable<string> repositories)
        {
            package = nugetName;

            //var nugetCacheDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet", "Cache");
            var nugetCacheDirectory = Path.Combine(AzureEnvironment.GetTempPath(), "packages");


            var reposToUse = new List<IPackageRepository>
            {
                PackageRepositoryFactory.Default.CreateRepository(nugetCacheDirectory)
            };

            reposToUse.AddRange(repositories.ToList().Select(r => PackageRepositoryFactory.Default.CreateRepository(r)));
            var repo = new AggregateRepository(reposToUse);

            packageManager = new PackageManager(repo, /*"packages"*/nugetCacheDirectory);
        }

        public List<string> DownloadAndExtractVersion(string version)
        {
            var semVer = SemanticVersion.Parse(version);

            packageManager.InstallPackage(package, semVer, true, false);

            var dirPath = Path.Combine(AzureEnvironment.GetTempPath(), "packages", string.Format("{0}.{1}", package, version), "lib");

            var netVersionDir = Directory.EnumerateDirectories(dirPath).FirstOrDefault(); //todo: how should we sort this?

            if (netVersionDir != null)
            {
                dirPath = netVersionDir;
            }

            var files = Directory.EnumerateFiles(dirPath)
                .Where(f => f.EndsWith(".dll") || f.EndsWith(".exe"))
                .ToList();


            if (!files.Any())
            {
                throw new Exception("Couldn't find any assemblies in  " + dirPath);
            }

            return files;
        }
    }
}
{'fraction_non_alphanumeric': 0.10652774824580055, 'fraction_numerical': 0.005103125664469487, 'mean_word_length': 2.1507032819825853, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6423451', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1200, 'n_words': 231}