@@ -80,67 +80,16 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
8080 this . nonGeneratedSources = allNonBinaryFiles . SelectFileNamesByExtension ( ".cs" ) . ToList ( ) ;
8181 this . generatedSources = new ( ) ;
8282 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 ( ) ;
13285
86+ RestoreNugetPackages ( allNonBinaryFiles , allProjects , allSolutions , dllPaths ) ;
13387 // 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 ) ;
14190
14291 assemblyCache = new AssemblyCache ( dllPaths , frameworkLocations , progressMonitor ) ;
143- AnalyseSolutions ( solutions ) ;
92+ AnalyseSolutions ( allSolutions ) ;
14493
14594 foreach ( var filename in assemblyCache . AllAssemblies . Select ( a => a . Filename ) )
14695 {
@@ -182,6 +131,58 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
182131 DateTime . Now - startTime ) ;
183132 }
184133
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+
185186 private static bool IsPathInSubfolder ( string path , string rootFolder , string subFolder )
186187 {
187188 return path . IndexOf (
@@ -192,11 +193,6 @@ private static bool IsPathInSubfolder(string path, string rootFolder, string sub
192193
193194 private void RemoveNugetAnalyzerReferences ( )
194195 {
195- if ( ! options . UseNuGet )
196- {
197- return ;
198- }
199-
200196 var packageFolder = packageDirectory . DirInfo . FullName . ToLowerInvariant ( ) ;
201197 if ( packageFolder == null )
202198 {
@@ -279,11 +275,7 @@ private void AddNetFrameworkDlls(ISet<string> dllPaths, ISet<string> frameworkLo
279275
280276 string ? runtimeLocation = null ;
281277
282- if ( options . UseSelfContainedDotnet )
283- {
284- runtimeLocation = Runtime . ExecutingRuntime ;
285- }
286- else if ( fileContent . IsNewProjectStructureUsed )
278+ if ( fileContent . IsNewProjectStructureUsed )
287279 {
288280 runtimeLocation = Runtime . NetCoreRuntime ;
289281 }
@@ -301,11 +293,6 @@ private void AddNetFrameworkDlls(ISet<string> dllPaths, ISet<string> frameworkLo
301293
302294 private void RemoveNugetPackageReference ( string packagePrefix , ISet < string > dllPaths )
303295 {
304- if ( ! options . UseNuGet )
305- {
306- return ;
307- }
308-
309296 var packageFolder = packageDirectory . DirInfo . FullName . ToLowerInvariant ( ) ;
310297 if ( packageFolder == null )
311298 {
@@ -353,11 +340,6 @@ private void AddMicrosoftWindowsDesktopDlls(ISet<string> dllPaths, ISet<string>
353340
354341 private string ? GetPackageDirectory ( string packagePrefix )
355342 {
356- if ( ! options . UseNuGet )
357- {
358- return null ;
359- }
360-
361343 return new DirectoryInfo ( packageDirectory . DirInfo . FullName )
362344 . EnumerateDirectories ( packagePrefix + "*" , new EnumerationOptions { MatchCasing = MatchCasing . CaseInsensitive , RecurseSubdirectories = false } )
363345 . FirstOrDefault ( ) ?
@@ -366,11 +348,6 @@ private void AddMicrosoftWindowsDesktopDlls(ISet<string> dllPaths, ISet<string>
366348
367349 private IEnumerable < string > GetAllPackageDirectories ( )
368350 {
369- if ( ! options . UseNuGet )
370- {
371- return Enumerable . Empty < string > ( ) ;
372- }
373-
374351 return new DirectoryInfo ( packageDirectory . DirInfo . FullName )
375352 . EnumerateDirectories ( "*" , new EnumerationOptions { MatchCasing = MatchCasing . CaseInsensitive , RecurseSubdirectories = false } )
376353 . Select ( d => d . Name ) ;
@@ -455,14 +432,14 @@ private void GenerateSourceFilesFromWebViews(List<FileInfo> allFiles)
455432
456433 private IEnumerable < FileInfo > GetAllFiles ( )
457434 {
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 } ) ;
460436
461437 if ( options . DotNetPath != null )
462438 {
463439 files = files . Where ( f => ! f . FullName . StartsWith ( options . DotNetPath , StringComparison . OrdinalIgnoreCase ) ) ;
464440 }
465441
442+ files = new FilePathFilter ( sourceDir , progressMonitor ) . Filter ( files ) ;
466443 return files ;
467444 }
468445
0 commit comments