Skip to content

Commit e72fa0e

Browse files
committed
add activities for some tool download-and-usage pathways
1 parent 5804b1c commit e72fa0e

23 files changed

+199
-132
lines changed

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ internal async Task<NewCommandStatus> InvokeAsync(ParseResult parseResult, Cance
156156
CancellationTokenSource cancellationTokenSource = new();
157157
cancellationTokenSource.CancelAfter(ConstraintEvaluationTimeout);
158158

159-
#pragma warning disable CA2025 // Do not pass 'IDisposable' instances into unawaited tasks
160159
Task<IReadOnlyList<TemplateConstraintResult>> constraintsEvaluation = ValidateConstraintsAsync(constraintManager, args.Template, args.IsForceFlagSpecified ? cancellationTokenSource.Token : cancellationToken);
161-
#pragma warning restore CA2025 // Do not pass 'IDisposable' instances into unawaited tasks
162160

163161
if (!args.IsForceFlagSpecified)
164162
{

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<root>
3-
<!--
4-
Microsoft ResX Schema
5-
3+
<!--
4+
Microsoft ResX Schema
5+
66
Version 2.0
7-
8-
The primary goals of this format is to allow a simple XML format
9-
that is mostly human readable. The generation and parsing of the
10-
various data types are done through the TypeConverter classes
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
1111
associated with the data types.
12-
12+
1313
Example:
14-
14+
1515
... ado.net/XML headers & schema ...
1616
<resheader name="resmimetype">text/microsoft-resx</resheader>
1717
<resheader name="version">2.0</resheader>
@@ -26,36 +26,36 @@
2626
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
2727
<comment>This is a comment</comment>
2828
</data>
29-
30-
There are any number of "resheader" rows that contain simple
29+
30+
There are any number of "resheader" rows that contain simple
3131
name/value pairs.
32-
33-
Each data row contains a name, and value. The row also contains a
34-
type or mimetype. Type corresponds to a .NET class that support
35-
text/value conversion through the TypeConverter architecture.
36-
Classes that don't support this are serialized and stored with the
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
3737
mimetype set.
38-
39-
The mimetype is used for serialized objects, and tells the
40-
ResXResourceReader how to depersist the object. This is currently not
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
4141
extensible. For a given mimetype the value must be set accordingly:
42-
43-
Note - application/x-microsoft.net.object.binary.base64 is the format
44-
that the ResXResourceWriter will generate, however the reader can
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
4545
read any of the formats listed below.
46-
46+
4747
mimetype: application/x-microsoft.net.object.binary.base64
48-
value : The object must be serialized with
48+
value : The object must be serialized with
4949
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
5050
: and then encoded with base64 encoding.
51-
51+
5252
mimetype: application/x-microsoft.net.object.soap.base64
53-
value : The object must be serialized with
53+
value : The object must be serialized with
5454
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
5555
: and then encoded with base64 encoding.
5656
5757
mimetype: application/x-microsoft.net.object.bytearray.base64
58-
value : The object must be serialized into a byte array
58+
value : The object must be serialized into a byte array
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
@@ -2628,6 +2628,9 @@ Proceed?</value>
26282628
<value>Tool package download needs confirmation. Run in interactive mode or use the "--yes" command-line option to confirm.</value>
26292629
<comment>{Locked="--yes"}</comment>
26302630
</data>
2631+
<data name="ToolInstallPackageIdMissing" xml:space="preserve">
2632+
<value>A package ID was not specified for tool installation.</value>
2633+
</data>
26312634
<data name="TestCommandUseSolution" xml:space="preserve">
26322635
<value>Specifying a solution for 'dotnet test' should be via '--solution'.</value>
26332636
</data>

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,23 @@ internal class ToolExecuteCommand(ParseResult result, ToolManifestFinder? toolMa
4141

4242
public override int Execute()
4343
{
44-
VersionRange versionRange = _parseResult.GetVersionRange();
44+
VersionRange? versionRange = _parseResult.GetVersionRange();
4545
PackageId packageId = new PackageId(_packageToolIdentityArgument.Id);
4646

47+
var toolLocationActivity = Activities.Source.StartActivity("find-tool");
48+
toolLocationActivity?.SetTag("packageId", packageId.ToString());
49+
toolLocationActivity?.SetTag("versionRange", versionRange?.ToString() ?? "latest");
50+
4751
// Look in local tools manifest first, but only if version is not specified
4852
if (versionRange == null)
4953
{
5054
var localToolsResolverCache = new LocalToolsResolverCache();
5155

5256
if (_toolManifestFinder.TryFindPackageId(packageId, out var toolManifestPackage))
5357
{
58+
toolLocationActivity?.SetTag("kind", "local");
59+
toolLocationActivity?.Stop();
60+
5461
var toolPackageRestorer = new ToolPackageRestorer(
5562
_toolPackageDownloader,
5663
_sources,
@@ -82,6 +89,8 @@ public override int Execute()
8289
additionalFeeds: _addSource);
8390

8491
(var bestVersion, var packageSource) = _toolPackageDownloader.GetNuGetVersion(packageLocation, packageId, _verbosity, versionRange, _restoreActionConfig);
92+
toolLocationActivity?.SetTag("kind", "one-shot");
93+
toolLocationActivity?.Stop();
8594

8695
// TargetFramework is null, which means to use the current framework. Global tools can override the target framework to use (or select assets for),
8796
// but we don't support this for local or one-shot tools.
@@ -119,6 +128,10 @@ public override int Execute()
119128
restoreActionConfig: _restoreActionConfig);
120129
}
121130

131+
using var toolExecuteActivity = Activities.Source.StartActivity("execute-tool");
132+
toolExecuteActivity?.SetTag("packageId", packageId.ToString());
133+
toolExecuteActivity?.SetTag("version", toolPackage.Version.ToString());
134+
toolExecuteActivity?.SetTag("source", toolPackage.Command.Runner);
122135
var commandSpec = ToolCommandSpecCreator.CreateToolCommandSpec(toolPackage.Command.Name.Value, toolPackage.Command.Executable.Value, toolPackage.Command.Runner, _allowRollForward, _forwardArguments);
123136
var command = CommandFactoryUsingResolver.Create(commandSpec);
124137
var result = command.Execute();

src/Cli/dotnet/Commands/Tool/Install/ParseResultExtension.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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-
64
using System.CommandLine;
75
using Microsoft.DotNet.Cli.Utils;
86
using NuGet.Versioning;
@@ -11,7 +9,7 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Install;
119

1210
internal static class ParseResultExtension
1311
{
14-
public static VersionRange GetVersionRange(this ParseResult parseResult)
12+
public static VersionRange? GetVersionRange(this ParseResult parseResult)
1513
{
1614
var packageVersionFromIdentityArgument = parseResult.GetValue(ToolInstallCommandParser.PackageIdentityArgument).VersionRange?.OriginalString;
1715
var packageVersionFromVersionOption = parseResult.GetValue(ToolInstallCommandParser.VersionOption);
@@ -22,7 +20,7 @@ public static VersionRange GetVersionRange(this ParseResult parseResult)
2220
throw new GracefulException(CliStrings.PackageIdentityArgumentVersionOptionConflict);
2321
}
2422

25-
string packageVersion = packageVersionFromIdentityArgument ?? packageVersionFromVersionOption;
23+
string? packageVersion = packageVersionFromIdentityArgument ?? packageVersionFromVersionOption;
2624

2725
bool prerelease = parseResult.GetValue(ToolInstallCommandParser.PrereleaseOption);
2826

@@ -39,10 +37,10 @@ public static VersionRange GetVersionRange(this ParseResult parseResult)
3937
packageVersion = "*-*";
4038
}
4139

42-
VersionRange versionRange = null;
40+
VersionRange? versionRange = null;
4341

4442
// accept 'bare' versions and interpret 'bare' versions as NuGet exact versions
45-
if (!string.IsNullOrEmpty(packageVersion) && NuGetVersion.TryParse(packageVersion, out NuGetVersion version2))
43+
if (!string.IsNullOrEmpty(packageVersion) && NuGetVersion.TryParse(packageVersion, out NuGetVersion? version2))
4644
{
4745
return new VersionRange(minVersion: version2, includeMinVersion: true, maxVersion: version2, includeMaxVersion: true, originalString: "[" + packageVersion + "]");
4846
}

0 commit comments

Comments
 (0)