dotnet-installer/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs

56 lines
1.8 KiB
C#
Raw Normal View History

2015-12-17 15:04:18 -08:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
namespace Microsoft.Extensions.DependencyModel
{
public class DependencyContext
{
private const string DepsResourceSufix = ".deps.json";
public DependencyContext(string target, string runtime, CompilationOptions compilationOptions, Library[] compileLibraries, Library[] runtimeLibraries)
2015-12-17 15:04:18 -08:00
{
Target = target;
Runtime = runtime;
CompilationOptions = compilationOptions;
2015-12-17 15:04:18 -08:00
CompileLibraries = compileLibraries;
RuntimeLibraries = runtimeLibraries;
}
public string Target { get; }
2015-12-17 15:04:18 -08:00
public string Runtime { get; }
public CompilationOptions CompilationOptions { get; }
2015-12-17 15:04:18 -08:00
public IReadOnlyList<Library> CompileLibraries { get; }
public IReadOnlyList<Library> RuntimeLibraries { get; }
public static DependencyContext Load()
{
var entryAssembly = (Assembly)typeof(Assembly).GetTypeInfo().GetDeclaredMethod("GetEntryAssembly").Invoke(null, null);
var stream = entryAssembly.GetManifestResourceStream(entryAssembly.GetName().Name + DepsResourceSufix);
if (stream == null)
{
throw new InvalidOperationException("Entry assembly was compiled without `preserveCompilationContext` enabled");
}
using (stream)
{
return Load(stream);
}
}
public static DependencyContext Load(Stream stream)
{
return new DependencyContextReader().Read(stream);
}
}
}