private async Task HandleMetapackage(string outpath, string package, string version)
        {
            var packageDir = await PackageDownloader.DownloadPackageIfNedeed(_configDir, package, version);

            var libs = GetRefInfos(packageDir, package, version);

            await GenerateBazelFile(outpath, libs);
        }
        private async Task Handle(string outpath, string package, string version, string sdkVersion, string sdk)
        {
            var packageDir = await PackageDownloader.DownloadPackageIfNedeed(_configDir, package, version);

            var sdkDir = await ZipDownloader.DownloadIfNedeed(_configDir, sdk);

            var refs = GetRefInfos(packageDir, package, version, sdkDir, sdkVersion);

            await GenerateBazelFile(outpath, refs);
        }
Exemple #3
0
        public override async Task <List <RefInfo> > GetRefInfos(string configDir)
        {
            var package = await PackageDownloader.DownloadPackageIfNedeed(configDir, "Microsoft.NETCore.App", InternalVersionFolder);

            var sdkDir = await ZipDownloader.DownloadIfNedeed(configDir, WindowsUrl);

            var brokenDependencies = new string[] { "netstandard" };

            var result = new List <RefInfo>();

            var packageDir   = Path.Combine(package, "packages", $"Microsoft.NETCore.App.{InternalVersionFolder}");
            var frameworkDir = Path.Combine(packageDir, "ref");

            frameworkDir = Directory.GetDirectories(frameworkDir).OrderByDescending(x => x).First();

            var relative = Path.GetRelativePath(packageDir, frameworkDir).Replace('\\', '/');
            var dlls     = Directory.GetFiles(frameworkDir, "*.dll");

            var resolver = new PathAssemblyResolver(dlls);

            using var lc = new MetadataLoadContext(resolver);
            var known = dlls.Select(x => Path.GetFileNameWithoutExtension(x).ToLower()).ToArray();

            foreach (var d in dlls)
            {
                try
                {
                    var metadata = lc.LoadFromAssemblyPath(d);
                    var deps     = metadata.GetReferencedAssemblies();
                    var depNames = deps
                                   .Where(y => !brokenDependencies.Contains(y.Name.ToLower()) && known.Contains(y.Name.ToLower()))
                                   .Select(x => $"\":{x.Name.ToLower()}.dll\"");
                    var name       = Path.GetFileName(d);
                    var refname    = $"@Microsoft.NETCore.App.{InternalVersionFolder}//:{relative}/{name}";
                    var stdlibpath = GetStdlibPath(sdkDir, name, InternalVersionFolder, Version);

                    var refInfo = new RefInfo();
                    refInfo.Name       = name.ToLower();
                    refInfo.Version    = metadata.GetName().Version.ToString();
                    refInfo.Ref        = refname;
                    refInfo.StdlibPath = stdlibpath;
                    refInfo.Pack       = null;
                    refInfo.Deps.AddRange(depNames);
                    result.Add(refInfo);
                }
                catch (Exception)
                {
                }
            }

            return(result);
        }