@@ -80,67 +80,16 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
80
80
this . nonGeneratedSources = allNonBinaryFiles . SelectFileNamesByExtension ( ".cs" ) . ToList ( ) ;
81
81
this . generatedSources = new ( ) ;
82
82
var allProjects = allNonBinaryFiles . SelectFileNamesByExtension ( ".csproj" ) ;
83
- var solutions = options . SolutionFile is not null
84
- ? new [ ] { options . SolutionFile }
85
- : allNonBinaryFiles . SelectFileNamesByExtension ( ".sln" ) ;
86
- var dllPaths = options . DllDirs . Count == 0
87
- ? allFiles . SelectFileNamesByExtension ( ".dll" ) . ToHashSet ( )
88
- : options . DllDirs . Select ( Path . GetFullPath ) . ToHashSet ( ) ;
89
-
90
- if ( options . UseNuGet )
91
- {
92
- try
93
- {
94
- var nuget = new NugetPackages ( sourceDir . FullName , legacyPackageDirectory , progressMonitor ) ;
95
- nuget . InstallPackages ( ) ;
96
-
97
- var nugetPackageDlls = legacyPackageDirectory . DirInfo . GetFiles ( "*.dll" , new EnumerationOptions { RecurseSubdirectories = true } ) ;
98
- var nugetPackageDllPaths = nugetPackageDlls . Select ( f => f . FullName ) . ToHashSet ( ) ;
99
- var excludedPaths = nugetPackageDllPaths
100
- . Where ( path => IsPathInSubfolder ( path , legacyPackageDirectory . DirInfo . FullName , "tools" ) ) ;
101
-
102
- foreach ( var excludedPath in excludedPaths )
103
- {
104
- progressMonitor . LogInfo ( $ "Excluded Nuget DLL: { excludedPath } ") ;
105
- }
106
-
107
- nugetPackageDllPaths . ExceptWith ( excludedPaths ) ;
108
- dllPaths . UnionWith ( nugetPackageDllPaths ) ;
109
- }
110
- catch ( FileNotFoundException )
111
- {
112
- progressMonitor . MissingNuGet ( ) ;
113
- }
114
-
115
- var restoredProjects = RestoreSolutions ( solutions , out var assets1 ) ;
116
- var projects = allProjects . Except ( restoredProjects ) ;
117
- RestoreProjects ( projects , out var assets2 ) ;
118
-
119
- var dependencies = Assets . GetCompilationDependencies ( progressMonitor , assets1 . Union ( assets2 ) ) ;
120
-
121
- var paths = dependencies
122
- . Paths
123
- . Select ( d => Path . Combine ( packageDirectory . DirInfo . FullName , d ) )
124
- . ToList ( ) ;
125
- dllPaths . UnionWith ( paths ) ;
126
-
127
- LogAllUnusedPackages ( dependencies ) ;
128
- DownloadMissingPackages ( allNonBinaryFiles , dllPaths ) ;
129
- }
130
-
131
- var frameworkLocations = new HashSet < string > ( ) ;
83
+ var allSolutions = allNonBinaryFiles . SelectFileNamesByExtension ( ".sln" ) ;
84
+ var dllPaths = allFiles . SelectFileNamesByExtension ( ".dll" ) . ToHashSet ( ) ;
132
85
86
+ RestoreNugetPackages ( allNonBinaryFiles , allProjects , allSolutions , dllPaths ) ;
133
87
// Find DLLs in the .Net / Asp.Net Framework
134
- // This block needs to come after the nuget restore, because the nuget restore might fetch the .NET Core/Framework reference assemblies.
135
- if ( options . ScanNetFrameworkDlls )
136
- {
137
- AddNetFrameworkDlls ( dllPaths , frameworkLocations ) ;
138
- AddAspNetCoreFrameworkDlls ( dllPaths , frameworkLocations ) ;
139
- AddMicrosoftWindowsDesktopDlls ( dllPaths , frameworkLocations ) ;
140
- }
88
+ // This needs to come after the nuget restore, because the nuget restore might fetch the .NET Core/Framework reference assemblies.
89
+ var frameworkLocations = AddFrameworkDlls ( dllPaths ) ;
141
90
142
91
assemblyCache = new AssemblyCache ( dllPaths , frameworkLocations , progressMonitor ) ;
143
- AnalyseSolutions ( solutions ) ;
92
+ AnalyseSolutions ( allSolutions ) ;
144
93
145
94
foreach ( var filename in assemblyCache . AllAssemblies . Select ( a => a . Filename ) )
146
95
{
@@ -182,6 +131,58 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
182
131
DateTime . Now - startTime ) ;
183
132
}
184
133
134
+ private HashSet < string > AddFrameworkDlls ( HashSet < string > dllPaths )
135
+ {
136
+ var frameworkLocations = new HashSet < string > ( ) ;
137
+
138
+ AddNetFrameworkDlls ( dllPaths , frameworkLocations ) ;
139
+ AddAspNetCoreFrameworkDlls ( dllPaths , frameworkLocations ) ;
140
+ AddMicrosoftWindowsDesktopDlls ( dllPaths , frameworkLocations ) ;
141
+
142
+ return frameworkLocations ;
143
+ }
144
+
145
+ private void RestoreNugetPackages ( List < FileInfo > allNonBinaryFiles , IEnumerable < string > allProjects , IEnumerable < string > allSolutions , HashSet < string > dllPaths )
146
+ {
147
+ try
148
+ {
149
+ var nuget = new NugetPackages ( sourceDir . FullName , legacyPackageDirectory , progressMonitor ) ;
150
+ nuget . InstallPackages ( ) ;
151
+
152
+ var nugetPackageDlls = legacyPackageDirectory . DirInfo . GetFiles ( "*.dll" , new EnumerationOptions { RecurseSubdirectories = true } ) ;
153
+ var nugetPackageDllPaths = nugetPackageDlls . Select ( f => f . FullName ) . ToHashSet ( ) ;
154
+ var excludedPaths = nugetPackageDllPaths
155
+ . Where ( path => IsPathInSubfolder ( path , legacyPackageDirectory . DirInfo . FullName , "tools" ) ) ;
156
+
157
+ foreach ( var excludedPath in excludedPaths )
158
+ {
159
+ progressMonitor . LogInfo ( $ "Excluded Nuget DLL: { excludedPath } ") ;
160
+ }
161
+
162
+ nugetPackageDllPaths . ExceptWith ( excludedPaths ) ;
163
+ dllPaths . UnionWith ( nugetPackageDllPaths ) ;
164
+ }
165
+ catch ( FileNotFoundException )
166
+ {
167
+ progressMonitor . MissingNuGet ( ) ;
168
+ }
169
+
170
+ var restoredProjects = RestoreSolutions ( allSolutions , out var assets1 ) ;
171
+ var projects = allProjects . Except ( restoredProjects ) ;
172
+ RestoreProjects ( projects , out var assets2 ) ;
173
+
174
+ var dependencies = Assets . GetCompilationDependencies ( progressMonitor , assets1 . Union ( assets2 ) ) ;
175
+
176
+ var paths = dependencies
177
+ . Paths
178
+ . Select ( d => Path . Combine ( packageDirectory . DirInfo . FullName , d ) )
179
+ . ToList ( ) ;
180
+ dllPaths . UnionWith ( paths ) ;
181
+
182
+ LogAllUnusedPackages ( dependencies ) ;
183
+ DownloadMissingPackages ( allNonBinaryFiles , dllPaths ) ;
184
+ }
185
+
185
186
private static bool IsPathInSubfolder ( string path , string rootFolder , string subFolder )
186
187
{
187
188
return path . IndexOf (
@@ -192,11 +193,6 @@ private static bool IsPathInSubfolder(string path, string rootFolder, string sub
192
193
193
194
private void RemoveNugetAnalyzerReferences ( )
194
195
{
195
- if ( ! options . UseNuGet )
196
- {
197
- return ;
198
- }
199
-
200
196
var packageFolder = packageDirectory . DirInfo . FullName . ToLowerInvariant ( ) ;
201
197
if ( packageFolder == null )
202
198
{
@@ -279,11 +275,7 @@ private void AddNetFrameworkDlls(ISet<string> dllPaths, ISet<string> frameworkLo
279
275
280
276
string ? runtimeLocation = null ;
281
277
282
- if ( options . UseSelfContainedDotnet )
283
- {
284
- runtimeLocation = Runtime . ExecutingRuntime ;
285
- }
286
- else if ( fileContent . IsNewProjectStructureUsed )
278
+ if ( fileContent . IsNewProjectStructureUsed )
287
279
{
288
280
runtimeLocation = Runtime . NetCoreRuntime ;
289
281
}
@@ -301,11 +293,6 @@ private void AddNetFrameworkDlls(ISet<string> dllPaths, ISet<string> frameworkLo
301
293
302
294
private void RemoveNugetPackageReference ( string packagePrefix , ISet < string > dllPaths )
303
295
{
304
- if ( ! options . UseNuGet )
305
- {
306
- return ;
307
- }
308
-
309
296
var packageFolder = packageDirectory . DirInfo . FullName . ToLowerInvariant ( ) ;
310
297
if ( packageFolder == null )
311
298
{
@@ -353,11 +340,6 @@ private void AddMicrosoftWindowsDesktopDlls(ISet<string> dllPaths, ISet<string>
353
340
354
341
private string ? GetPackageDirectory ( string packagePrefix )
355
342
{
356
- if ( ! options . UseNuGet )
357
- {
358
- return null ;
359
- }
360
-
361
343
return new DirectoryInfo ( packageDirectory . DirInfo . FullName )
362
344
. EnumerateDirectories ( packagePrefix + "*" , new EnumerationOptions { MatchCasing = MatchCasing . CaseInsensitive , RecurseSubdirectories = false } )
363
345
. FirstOrDefault ( ) ?
@@ -366,11 +348,6 @@ private void AddMicrosoftWindowsDesktopDlls(ISet<string> dllPaths, ISet<string>
366
348
367
349
private IEnumerable < string > GetAllPackageDirectories ( )
368
350
{
369
- if ( ! options . UseNuGet )
370
- {
371
- return Enumerable . Empty < string > ( ) ;
372
- }
373
-
374
351
return new DirectoryInfo ( packageDirectory . DirInfo . FullName )
375
352
. EnumerateDirectories ( "*" , new EnumerationOptions { MatchCasing = MatchCasing . CaseInsensitive , RecurseSubdirectories = false } )
376
353
. Select ( d => d . Name ) ;
@@ -455,14 +432,14 @@ private void GenerateSourceFilesFromWebViews(List<FileInfo> allFiles)
455
432
456
433
private IEnumerable < FileInfo > GetAllFiles ( )
457
434
{
458
- var files = sourceDir . GetFiles ( "*.*" , new EnumerationOptions { RecurseSubdirectories = true } )
459
- . Where ( d => ! options . ExcludesFile ( d . FullName ) ) ;
435
+ IEnumerable < FileInfo > files = sourceDir . GetFiles ( "*.*" , new EnumerationOptions { RecurseSubdirectories = true } ) ;
460
436
461
437
if ( options . DotNetPath != null )
462
438
{
463
439
files = files . Where ( f => ! f . FullName . StartsWith ( options . DotNetPath , StringComparison . OrdinalIgnoreCase ) ) ;
464
440
}
465
441
442
+ files = new FilePathFilter ( sourceDir , progressMonitor ) . Filter ( files ) ;
466
443
return files ;
467
444
}
468
445
0 commit comments