@@ -13,11 +13,11 @@ public class NugetAssemblyLocator
13
13
{
14
14
private const string PackageDirectoryName = "\\ packages\\ " ;
15
15
16
+ private readonly List < string > resolvedAssemblies = new List < string > ( ) ;
17
+
16
18
public static List < string > FrameworkFolders { get ; } = new List < string > ( new [ ] { "netstandard*" , "netcore*" , "net5*" , "net4*" } ) ;
17
19
public static List < string > NugetFolders { get ; } = new List < string > ( new [ ] { "lib" , "ref" } ) ;
18
20
19
- private readonly List < string > resolvedAssemblies = new List < string > ( ) ;
20
-
21
21
public List < SearchLocation > Locations { get ; }
22
22
public bool SkipResourceAssemblies { get ; set ; }
23
23
public bool SkipSystemAssemblies { get ; set ; }
@@ -53,8 +53,13 @@ public Assembly Locate(string search, bool loadDependencies)
53
53
public Assembly Locate ( string search , Version defaultVersion = null , bool loadDependencies = false , bool forceSearchOnDisk = false )
54
54
{
55
55
AssemblyInfo info = ( this . GetAssemblyInfoFromLongName ( search ) ?? this . GetAssemblyInfoFromPath ( search , defaultVersion ) ) ?? new AssemblyInfo ( search , defaultVersion ) ;
56
- if ( this . SkipResourceAssemblies && info . IsResource || this . SkipSystemAssemblies && info . Name . StartsWith ( "System." ) || info . Name == "netstandard" || info . Name == "mscorlib" )
56
+ if ( this . SkipResourceAssemblies && info . IsResource || info . Name == "netstandard" || info . Name == "mscorlib" )
57
+ {
58
+ return null ;
59
+ }
60
+ if ( this . SkipSystemAssemblies && info . Name . StartsWith ( "System." ) )
57
61
{
62
+ Logger . Trace ( $ "Search for { info . Name } skipped. Set { nameof ( this . SkipSystemAssemblies ) } to false to disable this behaviour.") ;
58
63
return null ;
59
64
}
60
65
Assembly assembly = AppDomain . CurrentDomain . GetAssemblies ( ) . FirstOrDefault ( x => x . GetName ( ) . Name == info . Name ) ;
@@ -73,15 +78,15 @@ public Assembly Locate(string search, Version defaultVersion = null, bool loadDe
73
78
}
74
79
if ( ! forceSearchOnDisk && info . Name . StartsWith ( "System." ) )
75
80
{
76
- assembly = AssemblyLoadContext . Default . LoadFromAssemblyName ( new AssemblyName ( search ) ) ;
77
- if ( assembly != null )
81
+ assembly = AssemblyLoadContext . Default . LoadFromAssemblyName ( new AssemblyName ( search ) ) ;
82
+ if ( assembly != null )
83
+ {
84
+ if ( loadDependencies )
78
85
{
79
- if ( loadDependencies )
80
- {
81
- this . ResolveDependencies ( assembly ) ;
82
- }
83
- return assembly ;
86
+ this . ResolveDependencies ( assembly ) ;
84
87
}
88
+ return assembly ;
89
+ }
85
90
}
86
91
Logger . Trace ( $ "Try to find assembly { info } ...") ;
87
92
List < SearchLocation > locations = this . CleanLocations ( this . Locations ) ;
@@ -109,21 +114,29 @@ public Assembly Locate(string search, Version defaultVersion = null, bool loadDe
109
114
List < PossibleLocation > possibleLocations = new List < PossibleLocation > ( ) ;
110
115
foreach ( SearchLocation location in locations . Where ( x => x . SearchByVersion ) )
111
116
{
117
+ List < PossibleLocation > foundLocations = new List < PossibleLocation > ( ) ;
112
118
DirectoryInfo packageDirectory = FileSystem . GetDirectoryInfo ( location . Path , info . Name ) ;
113
119
if ( packageDirectory . Exists )
114
120
{
115
121
packageDirectory . GetDirectories ( )
116
122
. Select ( x => new PossibleLocation ( x . FullName , this . Parse ( x . Name ) ) )
117
123
. Where ( x => x . Version != null )
118
- . ForEach ( possibleLocations . Add ) ;
124
+ . ForEach ( foundLocations . Add ) ;
119
125
}
120
126
FileSystem . GetDirectoryInfos ( location . Path , info . Name + "*" )
121
127
. Select ( x => new PossibleLocation ( x . FullName , this . Parse ( Regex . Replace ( x . Name , Regex . Escape ( info . Name ) , string . Empty , RegexOptions . IgnoreCase ) . Trim ( "." ) ) ) )
122
128
. Where ( x => x . Version != null )
123
- . ForEach ( possibleLocations . Add ) ;
129
+ . ForEach ( foundLocations . Add ) ;
130
+ if ( foundLocations . Count > 0 )
131
+ {
132
+ foundLocations . ForEach ( x => Logger . Trace ( $ "Assembly found in: { x . Path } ") ) ;
133
+ }
134
+ else
135
+ {
136
+ Logger . Trace ( $ "Assembly not found in: { location . Path } ") ;
137
+ }
124
138
}
125
139
possibleLocations = possibleLocations . OrderByDescending ( x => x . Version ) . ToList ( ) ;
126
- possibleLocations . ForEach ( x => Logger . Trace ( $ "Assembly found in: { x . Path } ") ) ;
127
140
PossibleLocation possibleLocation = possibleLocations . FirstOrDefault ( x => info . Version == null || x . Version . ToString ( ) == info . Version . ToString ( ) )
128
141
?? possibleLocations . FirstOrDefault ( x => x . Version . ToString ( 3 ) == info . Version . ToString ( 3 ) )
129
142
?? possibleLocations . FirstOrDefault ( x => x . Version . ToString ( 2 ) == info . Version . ToString ( 2 ) )
@@ -201,7 +214,7 @@ private Assembly TryFind(AssemblyInfo info, params string[] chunks)
201
214
}
202
215
catch ( TargetInvocationException )
203
216
{
204
- if ( DoNotTryToLoadDependenciesOnError )
217
+ if ( this . DoNotTryToLoadDependenciesOnError )
205
218
{
206
219
throw ;
207
220
}
0 commit comments