-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
CompilationLibrary.cs
89 lines (77 loc) · 2.94 KB
/
CompilationLibrary.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyModel.Resolution;
namespace Microsoft.Extensions.DependencyModel
{
public class CompilationLibrary : Library
{
public CompilationLibrary(string type,
string name,
string version,
string hash,
IEnumerable<string> assemblies,
IEnumerable<Dependency> dependencies,
bool serviceable)
: this(type, name, version, hash, assemblies, dependencies, serviceable, path: null, hashPath: null)
{
}
public CompilationLibrary(string type,
string name,
string version,
string hash,
IEnumerable<string> assemblies,
IEnumerable<Dependency> dependencies,
bool serviceable,
string path,
string hashPath)
: base(type, name, version, hash, dependencies, serviceable, path, hashPath)
{
if (assemblies == null)
{
throw new ArgumentNullException(nameof(assemblies));
}
Assemblies = assemblies.ToArray();
}
public IReadOnlyList<string> Assemblies { get; }
#if !NETSTANDARD1_3
internal static ICompilationAssemblyResolver DefaultResolver { get; } = new CompositeCompilationAssemblyResolver(new ICompilationAssemblyResolver[]
{
new AppBaseCompilationAssemblyResolver(),
new ReferenceAssemblyPathResolver(),
new PackageCompilationAssemblyResolver()
});
public IEnumerable<string> ResolveReferencePaths()
{
var assemblies = new List<string>();
return ResolveReferencePaths(DefaultResolver, assemblies);
}
public IEnumerable<string> ResolveReferencePaths(params ICompilationAssemblyResolver[] customResolvers)
{
var assemblies = new List<string>();
if (customResolvers?.Length > 0)
{
foreach (var resolver in customResolvers)
{
if (resolver.TryResolveAssemblyPaths(this, assemblies))
{
return assemblies;
}
}
}
return ResolveReferencePaths(DefaultResolver, assemblies);
}
private IEnumerable<string> ResolveReferencePaths(ICompilationAssemblyResolver resolver, List<string> assemblies)
{
if (!resolver.TryResolveAssemblyPaths(this, assemblies))
{
throw new InvalidOperationException($"Cannot find compilation library location for package '{Name}'");
}
return assemblies;
}
#endif
}
}