PR
This commit is contained in:
parent
7df754be36
commit
25d70c07c3
3 changed files with 35 additions and 58 deletions
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyModel
|
||||
{
|
||||
|
@ -19,9 +20,9 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
string runtime,
|
||||
bool isPortable,
|
||||
CompilationOptions compilationOptions,
|
||||
CompilationLibrary[] compileLibraries,
|
||||
RuntimeLibrary[] runtimeLibraries,
|
||||
IReadOnlyList<KeyValuePair<string, string[]>> runtimeGraph)
|
||||
IEnumerable<CompilationLibrary> compileLibraries,
|
||||
IEnumerable<RuntimeLibrary> runtimeLibraries,
|
||||
IEnumerable<KeyValuePair<string, string[]>> runtimeGraph)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
|
@ -52,9 +53,9 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
Runtime = runtime;
|
||||
IsPortable = isPortable;
|
||||
CompilationOptions = compilationOptions;
|
||||
CompileLibraries = compileLibraries;
|
||||
RuntimeLibraries = runtimeLibraries;
|
||||
RuntimeGraph = runtimeGraph;
|
||||
CompileLibraries = compileLibraries.ToArray();
|
||||
RuntimeLibraries = runtimeLibraries.ToArray();
|
||||
RuntimeGraph = runtimeGraph.ToArray();
|
||||
}
|
||||
|
||||
public static DependencyContext Default => _defaultContext.Value;
|
||||
|
|
|
@ -28,24 +28,26 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
|
||||
private DependencyContext Read(JObject root)
|
||||
{
|
||||
string runtime = string.Empty;
|
||||
string target = string.Empty;
|
||||
var runtime = string.Empty;
|
||||
var target = string.Empty;
|
||||
|
||||
var runtimeTargetInfo = ReadRuntimeTargetInfo(root);
|
||||
var libraryStubs = ReadLibraryStubs((JObject) root[DependencyContextStrings.LibrariesPropertyName]);
|
||||
var targetsObject = (IEnumerable<KeyValuePair<string, JToken>>) root[DependencyContextStrings.TargetsPropertyName];
|
||||
var targetsObject = (JObject) root[DependencyContextStrings.TargetsPropertyName];
|
||||
|
||||
JObject runtimeTarget = null;
|
||||
JObject compileTarget = null;
|
||||
if (targetsObject != null)
|
||||
{
|
||||
var compileTargetProperty = targetsObject.FirstOrDefault(t => !IsRuntimeTarget(t.Key));
|
||||
compileTarget = (JObject) compileTargetProperty.Value;
|
||||
target = compileTargetProperty.Key;
|
||||
var compileTargetProperty = targetsObject.Properties()
|
||||
.FirstOrDefault(p => !IsRuntimeTarget(p.Name));
|
||||
|
||||
compileTarget = (JObject)compileTargetProperty.Value;
|
||||
target = compileTargetProperty.Name;
|
||||
|
||||
if (!string.IsNullOrEmpty(runtimeTargetInfo.Name))
|
||||
{
|
||||
runtimeTarget = (JObject) targetsObject.FirstOrDefault(t => t.Key == runtimeTargetInfo.Name).Value;
|
||||
runtimeTarget = (JObject) targetsObject[runtimeTargetInfo.Name];
|
||||
if (runtimeTarget == null)
|
||||
{
|
||||
throw new FormatException($"Target with name {runtimeTargetInfo.Name} not found");
|
||||
|
|
|
@ -66,52 +66,26 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
{
|
||||
o[DependencyContextStrings.DefinesPropertyName] = new JArray(compilationOptions.Defines);
|
||||
}
|
||||
if (compilationOptions.LanguageVersion != null)
|
||||
{
|
||||
o[DependencyContextStrings.LanguageVersionPropertyName] = compilationOptions.LanguageVersion;
|
||||
}
|
||||
if (compilationOptions.Platform != null)
|
||||
{
|
||||
o[DependencyContextStrings.PlatformPropertyName] = compilationOptions.Platform;
|
||||
}
|
||||
if (compilationOptions.AllowUnsafe != null)
|
||||
{
|
||||
o[DependencyContextStrings.AllowUnsafePropertyName] = compilationOptions.AllowUnsafe;
|
||||
}
|
||||
if (compilationOptions.WarningsAsErrors != null)
|
||||
{
|
||||
o[DependencyContextStrings.WarningsAsErrorsPropertyName] = compilationOptions.WarningsAsErrors;
|
||||
}
|
||||
if (compilationOptions.Optimize != null)
|
||||
{
|
||||
o[DependencyContextStrings.OptimizePropertyName] = compilationOptions.Optimize;
|
||||
}
|
||||
if (compilationOptions.KeyFile != null)
|
||||
{
|
||||
o[DependencyContextStrings.KeyFilePropertyName] = compilationOptions.KeyFile;
|
||||
}
|
||||
if (compilationOptions.DelaySign != null)
|
||||
{
|
||||
o[DependencyContextStrings.DelaySignPropertyName] = compilationOptions.DelaySign;
|
||||
}
|
||||
if (compilationOptions.PublicSign != null)
|
||||
{
|
||||
o[DependencyContextStrings.PublicSignPropertyName] = compilationOptions.PublicSign;
|
||||
}
|
||||
if (compilationOptions.DebugType != null)
|
||||
{
|
||||
o[DependencyContextStrings.DebugTypePropertyName] = compilationOptions.DebugType;
|
||||
}
|
||||
if (compilationOptions.EmitEntryPoint != null)
|
||||
{
|
||||
o[DependencyContextStrings.EmitEntryPointPropertyName] = compilationOptions.EmitEntryPoint;
|
||||
}
|
||||
if (compilationOptions.GenerateXmlDocumentation != null)
|
||||
{
|
||||
o[DependencyContextStrings.GenerateXmlDocumentationPropertyName] = compilationOptions.GenerateXmlDocumentation;
|
||||
}
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.LanguageVersionPropertyName, compilationOptions.LanguageVersion);
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.PlatformPropertyName, compilationOptions.Platform);
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.AllowUnsafePropertyName, compilationOptions.AllowUnsafe);
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.WarningsAsErrorsPropertyName, compilationOptions.WarningsAsErrors);
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.OptimizePropertyName, compilationOptions.Optimize);
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.KeyFilePropertyName, compilationOptions.KeyFile);
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.DelaySignPropertyName, compilationOptions.DelaySign);
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.PublicSignPropertyName, compilationOptions.PublicSign);
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.EmitEntryPointPropertyName, compilationOptions.EmitEntryPoint);
|
||||
AddPropertyIfNotNull(o, DependencyContextStrings.GenerateXmlDocumentationPropertyName, compilationOptions.GenerateXmlDocumentation);
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddPropertyIfNotNull<T>(JObject o, string name, T value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
o[name] = value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private JObject WriteTargets(DependencyContext context)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue