Пример #1
0
        private static void MapToPackage(AssemblyShortName assemblyName, string id, string version, string depsJsonPath, IDictionary <AssemblyShortName, ISet <PackageInfo> > map)
        {
            var packageInfo    = new PackageInfo(id, version, depsJsonPath);
            var packageInfoSet = map.GetOrAdd(assemblyName, _ => new HashSet <PackageInfo>());

            if (packageInfoSet.Contains(packageInfo))
            {
                return;
            }

            FluentConsole.Gray.Line($"  {id}");
            FluentConsole.Gray.Line($"    {id}.{version}");
            packageInfoSet.Add(packageInfo);
        }
Пример #2
0
        private static AssemblyDetails GetAssemblyDetailsFromNuGetCache(
            AssemblyShortName name,
            IImmutableDictionary <AssemblyShortName, IImmutableSet <PackageInfo> > roslynPackageMap
            )
        {
            var packageInfoSet = roslynPackageMap.GetValueOrDefault(name);

            if (packageInfoSet == null)
            {
                throw new Exception($"Could not identify NuGet package for assembly '{name}' (in packages referenced by Roslyn).");
            }
            if (packageInfoSet.Count > 1)
            {
                throw new Exception($"Ambiguous match for NuGet package for assembly '{name}':\r\n  {string.Join("\r\n  ", packageInfoSet)}.");
            }

            var packageInfo = packageInfoSet.Single();

            FluentConsole.Gray.Line($"      {packageInfo.PackageId}.{packageInfo.PackageVersion}");
            var packageVersionPath = Path.Combine(LocalNuGetCachePath, packageInfo.PackageId, packageInfo.PackageVersion);

            var libPath       = Path.Combine(packageVersionPath, "lib");
            var frameworkPath = new DirectoryInfo(libPath)
                                .EnumerateDirectories()
                                .Where(f => SupportedFrameworkNames.ContainsKey(f.Name))
                                .OrderBy(f => SupportedFrameworkNames[f.Name])
                                .FirstOrDefault()
                                ?.FullName;

            if (frameworkPath == null)
            {
                throw new DirectoryNotFoundException($"Could not find compatible framework for assembly '{name}' in NuGet cache, under {libPath}.");
            }
            if (File.Exists(Path.Combine(frameworkPath, "_._")))
            {
                return(null);
            }

            var assemblyPath = Path.Combine(frameworkPath, name.Name + ".dll");

            if (!File.Exists(assemblyPath))
            {
                throw new FileNotFoundException($"Could not find assembly '{name}' in NuGet cache, at {assemblyPath}.", assemblyPath);
            }
            return(AssemblyDetails.ReadFrom(assemblyPath, readSymbolsIfExist: false));
        }