Skip to content

Commit 983d928

Browse files
committed
Add some diagnostic logging for tool exec
1 parent ec12df1 commit 983d928

File tree

7 files changed

+108
-95
lines changed

7 files changed

+108
-95
lines changed

src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ public override int Execute()
8484

8585
(var bestVersion, var packageSource) = _toolPackageDownloader.GetNuGetVersion(packageLocation, packageId, _verbosity, versionRange, _restoreActionConfig);
8686

87-
IToolPackage toolPackage;
88-
8987
// TargetFramework is null, which means to use the current framework. Global tools can override the target framework to use (or select assets for),
9088
// but we don't support this for local or one-shot tools.
91-
if (!_toolPackageDownloader.TryGetDownloadedTool(packageId, bestVersion, targetFramework: null, out toolPackage))
89+
if (!_toolPackageDownloader.TryGetDownloadedTool(packageId, bestVersion, targetFramework: null, verbosity: _verbosity, out var toolPackage))
9290
{
9391
if (!UserAgreedToRunFromSource(packageId, bestVersion, packageSource))
9492
{
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
4+
using System.Diagnostics.CodeAnalysis;
65
using Microsoft.DotNet.Cli.NuGetPackageDownloader;
76
using NuGet.Configuration;
87
using NuGet.Versioning;
@@ -14,25 +13,27 @@ internal interface IToolPackageDownloader
1413
IToolPackage InstallPackage(PackageLocation packageLocation,
1514
PackageId packageId,
1615
VerbosityOptions verbosity,
17-
VersionRange versionRange = null,
18-
string targetFramework = null,
16+
VersionRange? versionRange = null,
17+
string? targetFramework = null,
1918
bool isGlobalTool = false,
2019
bool isGlobalToolRollForward = false,
2120
bool verifySignatures = true,
22-
RestoreActionConfig restoreActionConfig = null
21+
RestoreActionConfig? restoreActionConfig = null
2322
);
2423

2524
(NuGetVersion version, PackageSource source) GetNuGetVersion(
2625
PackageLocation packageLocation,
2726
PackageId packageId,
2827
VerbosityOptions verbosity,
29-
VersionRange versionRange = null,
30-
RestoreActionConfig restoreActionConfig = null
28+
VersionRange? versionRange = null,
29+
RestoreActionConfig? restoreActionConfig = null
3130
);
3231

3332
bool TryGetDownloadedTool(
3433
PackageId packageId,
3534
NuGetVersion packageVersion,
36-
string targetFramework,
37-
out IToolPackage toolPackage);
35+
string? targetFramework,
36+
VerbosityOptions verbosity,
37+
[NotNullWhen(true)]
38+
out IToolPackage? toolPackage);
3839
}

src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
#nullable disable
5-
6-
using System.Reflection;
74
using Microsoft.DotNet.Cli.Extensions;
85
using Microsoft.DotNet.Cli.NuGetPackageDownloader;
96
using Microsoft.DotNet.Cli.Utils;
107
using Microsoft.Extensions.EnvironmentAbstractions;
118
using Microsoft.TemplateEngine.Utils;
12-
using Newtonsoft.Json.Linq;
139
using NuGet.Client;
14-
using NuGet.Commands;
1510
using NuGet.Common;
16-
using NuGet.Configuration;
1711
using NuGet.ContentModel;
1812
using NuGet.Frameworks;
1913
using NuGet.LibraryModel;
@@ -30,23 +24,23 @@ internal class ToolPackageDownloader : ToolPackageDownloaderBase
3024
{
3125
public ToolPackageDownloader(
3226
IToolPackageStore store,
33-
string runtimeJsonPathForTests = null,
34-
string currentWorkingDirectory = null
27+
string? runtimeJsonPathForTests = null,
28+
string? currentWorkingDirectory = null
3529
) : base(store, runtimeJsonPathForTests, currentWorkingDirectory, FileSystemWrapper.Default)
3630
{
3731
}
3832

3933
protected override INuGetPackageDownloader CreateNuGetPackageDownloader(
4034
bool verifySignatures,
4135
VerbosityOptions verbosity,
42-
RestoreActionConfig restoreActionConfig)
36+
RestoreActionConfig? restoreActionConfig)
4337
{
4438
ILogger verboseLogger = new NullLogger();
4539
if (verbosity.IsDetailedOrDiagnostic())
4640
{
4741
verboseLogger = new NuGetConsoleLogger();
4842
}
49-
43+
5044
return new NuGetPackageDownloader.NuGetPackageDownloader(
5145
new DirectoryPath(),
5246
verboseLogger: verboseLogger,
@@ -63,13 +57,14 @@ protected override NuGetVersion DownloadAndExtractPackage(
6357
string packagesRootPath,
6458
NuGetVersion packageVersion,
6559
PackageSourceLocation packageSourceLocation,
60+
VerbosityOptions verbosity,
6661
bool includeUnlisted = false
6762
)
6863
{
6964
var versionFolderPathResolver = new VersionFolderPathResolver(packagesRootPath);
7065

71-
string folderToDeleteOnFailure = null;
72-
return TransactionalAction.Run<NuGetVersion>(() =>
66+
string? folderToDeleteOnFailure = null;
67+
return TransactionalAction.Run(() =>
7368
{
7469
var packagePath = nugetPackageDownloader.DownloadPackageAsync(packageId, packageVersion, packageSourceLocation,
7570
includeUnlisted: includeUnlisted, downloadFolder: new DirectoryPath(packagesRootPath)).ConfigureAwait(false).GetAwaiter().GetResult();
@@ -86,11 +81,14 @@ protected override NuGetVersion DownloadAndExtractPackage(
8681

8782
var packageHash = Convert.ToBase64String(new CryptoHashProvider("SHA512").CalculateHash(reader.GetNuspec()));
8883
var hashPath = versionFolderPathResolver.GetHashPath(packageId.ToString(), version);
89-
90-
Directory.CreateDirectory(Path.GetDirectoryName(hashPath));
84+
Directory.CreateDirectory(Path.GetDirectoryName(hashPath)!);
9185
File.WriteAllText(hashPath, packageHash);
9286
}
9387

88+
if (verbosity.IsDetailedOrDiagnostic())
89+
{
90+
Reporter.Output.WriteLine($"Extracting package {packageId}@{packageVersion} to {packagePath}");
91+
}
9492
// Extract the package
9593
var nupkgDir = versionFolderPathResolver.GetInstallPath(packageId.ToString(), version);
9694
nugetPackageDownloader.ExtractPackageAsync(packagePath, new DirectoryPath(nupkgDir)).ConfigureAwait(false).GetAwaiter().GetResult();
@@ -111,7 +109,6 @@ protected override bool IsPackageInstalled(PackageId packageId, NuGetVersion pac
111109
NuGetv3LocalRepository nugetLocalRepository = new(packagesRootPath);
112110

113111
var package = nugetLocalRepository.FindPackage(packageId.ToString(), packageVersion);
114-
115112
return package != null;
116113
}
117114

@@ -126,7 +123,8 @@ protected override void CreateAssetFile(
126123
DirectoryPath packagesRootPath,
127124
string assetFilePath,
128125
string runtimeJsonGraph,
129-
string targetFramework = null
126+
VerbosityOptions verbosity,
127+
string? targetFramework = null
130128
)
131129
{
132130
// To get runtimeGraph:
@@ -222,7 +220,7 @@ protected static IEnumerable<LockFileItem> GetLockFileItems(
222220
protected static IEnumerable<LockFileItem> GetLockFileItems(
223221
IReadOnlyList<SelectionCriteria> criteria,
224222
ContentItemCollection items,
225-
Action<LockFileItem> additionalAction,
223+
Action<LockFileItem>? additionalAction,
226224
params PatternSet[] patterns)
227225
{
228226
// Loop through each criteria taking the first one that matches one or more items.

0 commit comments

Comments
 (0)