@@ -39,7 +39,7 @@ private static async Task<int> Main(FileInfo package, bool verbose)
39
39
return 1 ;
40
40
}
41
41
42
- var dependencies = await DownloadNugetPackageDependenciesAsync ( packageReader , verbose ) ;
42
+ var dependencies = await DownloadNugetPackageDependenciesAsync ( packageReader , package . DirectoryName , verbose ) ;
43
43
Console . WriteLine ( "Downloaded all dependencies" ) ;
44
44
foreach ( var tfm in supportedFrameworks )
45
45
{
@@ -325,7 +325,7 @@ private static bool CheckNetstandardToNetFxTypeForwards(PackageReaderBase packag
325
325
}
326
326
}
327
327
328
- private static async Task < Dictionary < NuGetFramework , List < string > > > DownloadNugetPackageDependenciesAsync ( PackageReaderBase packageReader , bool verbose )
328
+ private static async Task < Dictionary < NuGetFramework , List < string > > > DownloadNugetPackageDependenciesAsync ( PackageReaderBase packageReader , string packageLocation , bool verbose )
329
329
{
330
330
Dictionary < NuGetFramework , List < string > > dependencies = new ( ) ;
331
331
@@ -338,7 +338,7 @@ private static async Task<Dictionary<NuGetFramework, List<string>>> DownloadNuge
338
338
if ( verbose ) { Console . WriteLine ( $ "Getting dependencies for tfm: { tfm . GetFrameworkString ( ) } ") ; }
339
339
foreach ( var dependency in group . Packages )
340
340
{
341
- List < string > implementationPath = await DownloadNugetPackageAndGetImplementationPathsAsync ( dependency , group . TargetFramework , verbose ) ;
341
+ List < string > implementationPath = await DownloadNugetPackageAndGetImplementationPathsAsync ( dependency , group . TargetFramework , packageLocation , verbose ) ;
342
342
if ( implementationPath == null )
343
343
{
344
344
Console . Error . WriteLine ( $ "Failed to download { dependency . Id } { dependency . VersionRange } for { tfm } , may fail later") ;
@@ -365,17 +365,30 @@ private static async Task<Dictionary<NuGetFramework, List<string>>> DownloadNuge
365
365
return dependencies ;
366
366
}
367
367
368
- private static async Task < List < string > > DownloadNugetPackageAndGetImplementationPathsAsync ( PackageDependency dependency , NuGetFramework tfm , bool verbose )
368
+ private static async Task < List < string > > DownloadNugetPackageAndGetImplementationPathsAsync ( PackageDependency dependency , NuGetFramework tfm , string packageLocation , bool verbose )
369
369
{
370
370
// TODO: Wire up proper logging
371
371
// TODO: Wire up proper cancellation token
372
372
373
+ bool isServiceModelDependency = dependency . Id . StartsWith ( "System.ServiceModel." ) ;
374
+
373
375
// Define the package sources
374
- var packageSources = new List < PackageSource >
376
+ List < PackageSource > packageSources ;
377
+ if ( isServiceModelDependency )
378
+ {
379
+ packageSources = new List < PackageSource >
380
+ {
381
+ new PackageSource ( packageLocation )
382
+ } ;
383
+ }
384
+ else
375
385
{
376
- new PackageSource ( "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" ) ,
377
- new PackageSource ( "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" )
378
- } ;
386
+ packageSources = new List < PackageSource >
387
+ {
388
+ new PackageSource ( "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" ) ,
389
+ new PackageSource ( "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" )
390
+ } ;
391
+ }
379
392
380
393
// Create the source repositories
381
394
var sourceRepositories = new List < SourceRepository > ( ) ;
@@ -387,32 +400,50 @@ private static async Task<List<string>> DownloadNugetPackageAndGetImplementation
387
400
var logger = NullLogger . Instance ;
388
401
var cacheContext = new SourceCacheContext ( ) ;
389
402
var downloadContext = new PackageDownloadContext ( cacheContext ) ;
390
- var globalPackagesFolder = SettingsUtility . GetGlobalPackagesFolder ( Settings . LoadDefaultSettings ( null ) ) ;
403
+ string packagesDownloadFolder ;
404
+ if ( isServiceModelDependency )
405
+ {
406
+ packagesDownloadFolder = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
407
+ Directory . CreateDirectory ( packagesDownloadFolder ) ;
408
+ if ( verbose ) { Console . WriteLine ( $ "Using temporary packages folder { packagesDownloadFolder } to install { dependency . Id } ") ; }
409
+ }
410
+ else
411
+ {
412
+ packagesDownloadFolder = SettingsUtility . GetGlobalPackagesFolder ( Settings . LoadDefaultSettings ( null ) ) ;
413
+ }
391
414
392
415
// Loop through the repositories to find and download the package
393
416
foreach ( var repository in sourceRepositories )
394
417
{
395
- var findPackageByIdResource = await repository . GetResourceAsync < FindPackageByIdResource > ( ) ;
396
- // Find all versions that match the version range
397
- var allVersions = await findPackageByIdResource . GetAllVersionsAsync ( dependency . Id , cacheContext , logger , default ) ;
398
- if ( allVersions == null )
418
+ NuGetVersion matchedVersion ;
419
+ if ( isServiceModelDependency )
399
420
{
400
- if ( verbose ) { Console . WriteLine ( $ "Didn't find package { dependency . Id } in repository { repository . PackageSource . SourceUri } ") ; }
401
- continue ;
421
+ matchedVersion = dependency . VersionRange . MinVersion ;
402
422
}
403
- var matchedVersion = allVersions . Where ( dependency . VersionRange . Satisfies ) . OrderByDescending ( v => v ) . FirstOrDefault ( ) ;
404
- if ( matchedVersion == null )
423
+ else
405
424
{
406
- if ( verbose ) { Console . WriteLine ( $ "No version found that satisfies the { dependency . Id } package version range { dependency . VersionRange . ToNormalizedString ( ) } .") ; }
407
- continue ;
425
+ var findPackageByIdResource = await repository . GetResourceAsync < FindPackageByIdResource > ( ) ;
426
+ // Find all versions that match the version range
427
+ var allVersions = await findPackageByIdResource . GetAllVersionsAsync ( dependency . Id , cacheContext , logger , default ) ;
428
+ if ( allVersions == null )
429
+ {
430
+ if ( verbose ) { Console . WriteLine ( $ "Didn't find package { dependency . Id } in repository { repository . PackageSource . SourceUri } ") ; }
431
+ continue ;
432
+ }
433
+ matchedVersion = allVersions . Where ( dependency . VersionRange . Satisfies ) . OrderByDescending ( v => v ) . FirstOrDefault ( ) ;
434
+ if ( matchedVersion == null )
435
+ {
436
+ if ( verbose ) { Console . WriteLine ( $ "No version found that satisfies the { dependency . Id } package version range { dependency . VersionRange . ToNormalizedString ( ) } .") ; }
437
+ continue ;
438
+ }
408
439
}
409
440
410
441
// Get the DownloadResource and download the package
411
442
var downloadResource = await repository . GetResourceAsync < DownloadResource > ( ) ;
412
443
var downloadResult = await downloadResource . GetDownloadResourceResultAsync (
413
444
new PackageIdentity ( dependency . Id , matchedVersion ) ,
414
445
downloadContext ,
415
- globalPackagesFolder ,
446
+ packagesDownloadFolder ,
416
447
logger ,
417
448
CancellationToken . None ) ;
418
449
@@ -425,14 +456,35 @@ private static async Task<List<string>> DownloadNugetPackageAndGetImplementation
425
456
return null ; // Returning instead of continuing as we found the package with the right version but no compatible TFM. We won't find the right version elsewhere.
426
457
}
427
458
428
- var packageExtractPath = Path . Combine ( globalPackagesFolder , dependency . Id , matchedVersion . ToNormalizedString ( ) ) ;
459
+ var packageExtractPath = Path . Combine ( packagesDownloadFolder , dependency . Id , matchedVersion . ToNormalizedString ( ) ) ;
429
460
var libItems = downloadResult . PackageReader . GetLibItems ( ) . Where ( fsg => fsg . TargetFramework . Equals ( packageTfmToUse ) ) . FirstOrDefault ( ) ;
430
461
if ( libItems == null )
431
462
{
432
463
Console . WriteLine ( $ "No lib items found for { packageTfmToUse } in { dependency . Id } { matchedVersion } ") ;
433
464
return null ;
434
465
}
435
466
467
+ if ( isServiceModelDependency )
468
+ {
469
+ // GetDownloadResourceResultAsync doesn't extract the package if it's local, so we need to do it ourselves
470
+ Directory . CreateDirectory ( packageExtractPath ) ;
471
+ foreach ( var file in libItems . Items . Where ( i => i . EndsWith ( ".dll" , StringComparison . OrdinalIgnoreCase ) ) )
472
+ {
473
+ var targetPath = Path . Combine ( packageExtractPath , file ) ;
474
+ var directoryPath = Path . GetDirectoryName ( targetPath ) ;
475
+ if ( ! string . IsNullOrEmpty ( directoryPath ) )
476
+ {
477
+ Directory . CreateDirectory ( directoryPath ) ;
478
+ }
479
+
480
+ using ( var fileStream = downloadResult . PackageReader . GetStream ( file ) )
481
+ using ( var outStream = new FileStream ( targetPath , FileMode . Create , FileAccess . Write , FileShare . None ) )
482
+ {
483
+ await fileStream . CopyToAsync ( outStream ) ;
484
+ }
485
+ }
486
+ }
487
+
436
488
return libItems . Items . Where ( i => i . EndsWith ( ".dll" , StringComparison . OrdinalIgnoreCase ) ) . Select ( i => Path . Combine ( packageExtractPath , i ) ) . ToList ( ) ;
437
489
}
438
490
}
0 commit comments