@@ -82,8 +82,8 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
82
82
? new [ ] { options . SolutionFile }
83
83
: allNonBinaryFiles . SelectFileNamesByExtension ( ".sln" ) ;
84
84
var dllPaths = options . DllDirs . Count == 0
85
- ? allFiles . SelectFileNamesByExtension ( ".dll" ) . ToList ( )
86
- : options . DllDirs . Select ( Path . GetFullPath ) . ToList ( ) ;
85
+ ? allFiles . SelectFileNamesByExtension ( ".dll" ) . ToHashSet ( )
86
+ : options . DllDirs . Select ( Path . GetFullPath ) . ToHashSet ( ) ;
87
87
88
88
if ( options . UseNuGet )
89
89
{
@@ -107,7 +107,7 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
107
107
. RequiredPaths
108
108
. Select ( d => Path . Combine ( packageDirectory . DirInfo . FullName , d ) )
109
109
. ToList ( ) ;
110
- dllPaths . AddRange ( paths ) ;
110
+ dllPaths . UnionWith ( paths ) ;
111
111
112
112
LogAllUnusedPackages ( dependencies ) ;
113
113
DownloadMissingPackages ( allNonBinaryFiles , dllPaths ) ;
@@ -205,7 +205,7 @@ private void RemoveNugetAnalyzerReferences()
205
205
}
206
206
}
207
207
208
- private void AddNetFrameworkDlls ( List < string > dllPaths )
208
+ private void AddNetFrameworkDlls ( ISet < string > dllPaths )
209
209
{
210
210
// Multiple dotnet framework packages could be present.
211
211
// The order of the packages is important, we're adding the first one that is present in the nuget cache.
@@ -218,13 +218,19 @@ private void AddNetFrameworkDlls(List<string> dllPaths)
218
218
} ;
219
219
220
220
var frameworkPath = packagesInPrioOrder
221
- . Select ( GetPackageDirectory )
222
- . FirstOrDefault ( dir => dir is not null ) ;
221
+ . Select ( ( s , index ) => ( Index : index , Path : GetPackageDirectory ( s ) ) )
222
+ . FirstOrDefault ( pair => pair . Path is not null ) ;
223
223
224
- if ( frameworkPath is not null )
224
+ if ( frameworkPath . Path is not null )
225
225
{
226
- dllPaths . Add ( frameworkPath ) ;
227
- progressMonitor . LogInfo ( "Found .NET Core/Framework DLLs in NuGet packages. Not adding installation directory." ) ;
226
+ dllPaths . Add ( frameworkPath . Path ) ;
227
+ progressMonitor . LogInfo ( $ "Found .NET Core/Framework DLLs in NuGet packages at { frameworkPath . Path } . Not adding installation directory.") ;
228
+
229
+ for ( var i = frameworkPath . Index + 1 ; i < packagesInPrioOrder . Length ; i ++ )
230
+ {
231
+ RemoveNugetPackageReference ( packagesInPrioOrder [ i ] , dllPaths ) ;
232
+ }
233
+
228
234
return ;
229
235
}
230
236
@@ -249,7 +255,29 @@ private void AddNetFrameworkDlls(List<string> dllPaths)
249
255
dllPaths . Add ( runtimeLocation ) ;
250
256
}
251
257
252
- private void AddAspNetCoreFrameworkDlls ( List < string > dllPaths )
258
+ private void RemoveNugetPackageReference ( string packagePrefix , ISet < string > dllPaths )
259
+ {
260
+ if ( ! options . UseNuGet )
261
+ {
262
+ return ;
263
+ }
264
+
265
+ var packageFolder = packageDirectory . DirInfo . FullName . ToLowerInvariant ( ) ;
266
+ if ( packageFolder == null )
267
+ {
268
+ return ;
269
+ }
270
+
271
+ var packagePathPrefix = Path . Combine ( packageFolder , packagePrefix . ToLowerInvariant ( ) ) ;
272
+ var toRemove = dllPaths . Where ( s => s . ToLowerInvariant ( ) . StartsWith ( packagePathPrefix ) ) ;
273
+ foreach ( var path in toRemove )
274
+ {
275
+ dllPaths . Remove ( path ) ;
276
+ progressMonitor . RemovedReference ( path ) ;
277
+ }
278
+ }
279
+
280
+ private void AddAspNetCoreFrameworkDlls ( ISet < string > dllPaths )
253
281
{
254
282
if ( ! fileContent . IsNewProjectStructureUsed || ! fileContent . UseAspNetCoreDlls )
255
283
{
@@ -269,7 +297,7 @@ private void AddAspNetCoreFrameworkDlls(List<string> dllPaths)
269
297
}
270
298
}
271
299
272
- private void AddMicrosoftWindowsDesktopDlls ( List < string > dllPaths )
300
+ private void AddMicrosoftWindowsDesktopDlls ( ISet < string > dllPaths )
273
301
{
274
302
if ( GetPackageDirectory ( "microsoft.windowsdesktop.app.ref" ) is string windowsDesktopApp )
275
303
{
@@ -628,7 +656,7 @@ private void RestoreProjects(IEnumerable<string> projects, out IEnumerable<strin
628
656
assets = assetFiles ;
629
657
}
630
658
631
- private void DownloadMissingPackages ( List < FileInfo > allFiles , List < string > dllPaths )
659
+ private void DownloadMissingPackages ( List < FileInfo > allFiles , ISet < string > dllPaths )
632
660
{
633
661
var nugetConfigs = allFiles . SelectFileNamesByName ( "nuget.config" ) . ToArray ( ) ;
634
662
string ? nugetConfig = null ;
0 commit comments