Skip to content

Instantly share code, notes, and snippets.

@devhawk
Created December 18, 2019 21:29
Show Gist options
  • Select an option

  • Save devhawk/6266f29181e822a09de7874d0842f5ec to your computer and use it in GitHub Desktop.

Select an option

Save devhawk/6266f29181e822a09de7874d0842f5ec to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.DependencyModel;
using Microsoft.Extensions.DependencyModel.Resolution;
namespace TestDependencyModel
{
class Program
{
const string PATH = @"<path to contract.deps.json file here>";
public static void Main(string[] args)
{
using var stream = File.OpenRead(PATH);
var reader = new DependencyContextJsonReader();
var dc = reader.Read(stream);
var resolver = new CompositeCompilationAssemblyResolver(
new ICompilationAssemblyResolver[]
{
new AppBaseCompilationAssemblyResolver(Path.GetDirectoryName(PATH)),
new ReferenceAssemblyPathResolver(),
new PackageCompilationAssemblyResolver()
});
foreach (var library in dc.RuntimeLibraries)
{
var cl = new CompilationLibrary(
library.Type,
library.Name,
library.Version,
library.Hash,
library.RuntimeAssemblyGroups.SelectMany(g => g.AssetPaths),
library.Dependencies,
library.Serviceable);
var assemblies = new List<string>();
resolver.TryResolveAssemblyPaths(cl, assemblies);
Console.WriteLine($"{library.Name} ({library.Type})");
foreach (var a in assemblies)
{
Console.WriteLine($" {a}");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment