1
1
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
- #nullable disable
5
-
6
- using System . Reflection ;
7
4
using Microsoft . DotNet . Cli . Extensions ;
8
5
using Microsoft . DotNet . Cli . NuGetPackageDownloader ;
9
6
using Microsoft . DotNet . Cli . Utils ;
10
7
using Microsoft . Extensions . EnvironmentAbstractions ;
11
8
using Microsoft . TemplateEngine . Utils ;
12
- using Newtonsoft . Json . Linq ;
13
9
using NuGet . Client ;
14
- using NuGet . Commands ;
15
10
using NuGet . Common ;
16
- using NuGet . Configuration ;
17
11
using NuGet . ContentModel ;
18
12
using NuGet . Frameworks ;
19
13
using NuGet . LibraryModel ;
@@ -30,23 +24,23 @@ internal class ToolPackageDownloader : ToolPackageDownloaderBase
30
24
{
31
25
public ToolPackageDownloader (
32
26
IToolPackageStore store ,
33
- string runtimeJsonPathForTests = null ,
34
- string currentWorkingDirectory = null
27
+ string ? runtimeJsonPathForTests = null ,
28
+ string ? currentWorkingDirectory = null
35
29
) : base ( store , runtimeJsonPathForTests , currentWorkingDirectory , FileSystemWrapper . Default )
36
30
{
37
31
}
38
32
39
33
protected override INuGetPackageDownloader CreateNuGetPackageDownloader (
40
34
bool verifySignatures ,
41
35
VerbosityOptions verbosity ,
42
- RestoreActionConfig restoreActionConfig )
36
+ RestoreActionConfig ? restoreActionConfig )
43
37
{
44
38
ILogger verboseLogger = new NullLogger ( ) ;
45
39
if ( verbosity . IsDetailedOrDiagnostic ( ) )
46
40
{
47
41
verboseLogger = new NuGetConsoleLogger ( ) ;
48
42
}
49
-
43
+
50
44
return new NuGetPackageDownloader . NuGetPackageDownloader (
51
45
new DirectoryPath ( ) ,
52
46
verboseLogger : verboseLogger ,
@@ -63,13 +57,14 @@ protected override NuGetVersion DownloadAndExtractPackage(
63
57
string packagesRootPath ,
64
58
NuGetVersion packageVersion ,
65
59
PackageSourceLocation packageSourceLocation ,
60
+ VerbosityOptions verbosity ,
66
61
bool includeUnlisted = false
67
62
)
68
63
{
69
64
var versionFolderPathResolver = new VersionFolderPathResolver ( packagesRootPath ) ;
70
65
71
- string folderToDeleteOnFailure = null ;
72
- return TransactionalAction . Run < NuGetVersion > ( ( ) =>
66
+ string ? folderToDeleteOnFailure = null ;
67
+ return TransactionalAction . Run ( ( ) =>
73
68
{
74
69
var packagePath = nugetPackageDownloader . DownloadPackageAsync ( packageId , packageVersion , packageSourceLocation ,
75
70
includeUnlisted : includeUnlisted , downloadFolder : new DirectoryPath ( packagesRootPath ) ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
@@ -86,11 +81,14 @@ protected override NuGetVersion DownloadAndExtractPackage(
86
81
87
82
var packageHash = Convert . ToBase64String ( new CryptoHashProvider ( "SHA512" ) . CalculateHash ( reader . GetNuspec ( ) ) ) ;
88
83
var hashPath = versionFolderPathResolver . GetHashPath ( packageId . ToString ( ) , version ) ;
89
-
90
- Directory . CreateDirectory ( Path . GetDirectoryName ( hashPath ) ) ;
84
+ Directory . CreateDirectory ( Path . GetDirectoryName ( hashPath ) ! ) ;
91
85
File . WriteAllText ( hashPath , packageHash ) ;
92
86
}
93
87
88
+ if ( verbosity . IsDetailedOrDiagnostic ( ) )
89
+ {
90
+ Reporter . Output . WriteLine ( $ "Extracting package { packageId } @{ packageVersion } to { packagePath } ") ;
91
+ }
94
92
// Extract the package
95
93
var nupkgDir = versionFolderPathResolver . GetInstallPath ( packageId . ToString ( ) , version ) ;
96
94
nugetPackageDownloader . ExtractPackageAsync ( packagePath , new DirectoryPath ( nupkgDir ) ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
@@ -111,7 +109,6 @@ protected override bool IsPackageInstalled(PackageId packageId, NuGetVersion pac
111
109
NuGetv3LocalRepository nugetLocalRepository = new ( packagesRootPath ) ;
112
110
113
111
var package = nugetLocalRepository . FindPackage ( packageId . ToString ( ) , packageVersion ) ;
114
-
115
112
return package != null ;
116
113
}
117
114
@@ -126,7 +123,8 @@ protected override void CreateAssetFile(
126
123
DirectoryPath packagesRootPath ,
127
124
string assetFilePath ,
128
125
string runtimeJsonGraph ,
129
- string targetFramework = null
126
+ VerbosityOptions verbosity ,
127
+ string ? targetFramework = null
130
128
)
131
129
{
132
130
// To get runtimeGraph:
@@ -222,7 +220,7 @@ protected static IEnumerable<LockFileItem> GetLockFileItems(
222
220
protected static IEnumerable < LockFileItem > GetLockFileItems (
223
221
IReadOnlyList < SelectionCriteria > criteria ,
224
222
ContentItemCollection items ,
225
- Action < LockFileItem > additionalAction ,
223
+ Action < LockFileItem > ? additionalAction ,
226
224
params PatternSet [ ] patterns )
227
225
{
228
226
// Loop through each criteria taking the first one that matches one or more items.
0 commit comments