Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 7ebfdde

Browse files
author
Peter Huene
committed
Add verbosity option to install tool command.
This commit adds the `--verbosity` option to the `install tool` command. MSBuild/NuGet output is now controllable by the user and defaults to being "quiet". This enables users to see warnings from NuGet that otherwise would be swallowed unless NuGet returned a non-zero exit code. As a byproduct of this change, the exception handling and error messages related to obtaining tool packages was retooled. We no longer display `install tool` command line help for installation failures, as it should only be displayed for command line syntax errors. Fixes #8465.
1 parent 085452e commit 7ebfdde

File tree

50 files changed

+1066
-1101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1066
-1101
lines changed

Microsoft.DotNet.Cli.sln

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 15
33
VisualStudioVersion = 15.0.27130.2020
44
MinimumVisualStudioVersion = 10.0.40219.1
@@ -236,6 +236,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Tools.Test
236236
EndProject
237237
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "tool_launcher", "src\tool_launcher\tool_launcher.csproj", "{EDF19BE6-F20F-4AD0-8E3B-E837030726A5}"
238238
EndProject
239+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-install-tool.Tests", "test\dotnet-install-tool.Tests\dotnet-install-tool.Tests.csproj", "{8FE9D802-57F3-493B-9E14-72DF905E3838}"
240+
EndProject
239241
Global
240242
GlobalSection(SolutionConfigurationPlatforms) = preSolution
241243
Debug|Any CPU = Debug|Any CPU
@@ -1692,6 +1694,30 @@ Global
16921694
{E442F4C1-08DB-470F-B9A6-197444CD0295}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
16931695
{E442F4C1-08DB-470F-B9A6-197444CD0295}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU
16941696
{E442F4C1-08DB-470F-B9A6-197444CD0295}.RelWithDebInfo|x86.Build.0 = Release|Any CPU
1697+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1698+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Debug|Any CPU.Build.0 = Debug|Any CPU
1699+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Debug|x64.ActiveCfg = Debug|Any CPU
1700+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Debug|x64.Build.0 = Debug|Any CPU
1701+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Debug|x86.ActiveCfg = Debug|Any CPU
1702+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Debug|x86.Build.0 = Debug|Any CPU
1703+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
1704+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
1705+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
1706+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.MinSizeRel|x64.Build.0 = Debug|Any CPU
1707+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU
1708+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.MinSizeRel|x86.Build.0 = Debug|Any CPU
1709+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Release|Any CPU.ActiveCfg = Release|Any CPU
1710+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Release|Any CPU.Build.0 = Release|Any CPU
1711+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Release|x64.ActiveCfg = Release|Any CPU
1712+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Release|x64.Build.0 = Release|Any CPU
1713+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Release|x86.ActiveCfg = Release|Any CPU
1714+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.Release|x86.Build.0 = Release|Any CPU
1715+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
1716+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
1717+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
1718+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
1719+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.RelWithDebInfo|x86.ActiveCfg = Debug|Any CPU
1720+
{8FE9D802-57F3-493B-9E14-72DF905E3838}.RelWithDebInfo|x86.Build.0 = Debug|Any CPU
16951721
EndGlobalSection
16961722
GlobalSection(SolutionProperties) = preSolution
16971723
HideSolutionNode = FALSE
@@ -1767,6 +1793,7 @@ Global
17671793
{91BFE800-1624-4A58-A1CE-339705A8FFD0} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
17681794
{EDF19BE6-F20F-4AD0-8E3B-E837030726A5} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
17691795
{E442F4C1-08DB-470F-B9A6-197444CD0295} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
1796+
{8FE9D802-57F3-493B-9E14-72DF905E3838} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
17701797
EndGlobalSection
17711798
GlobalSection(ExtensibilityGlobals) = postSolution
17721799
SolutionGuid = {B526D2CE-EE2D-4AD4-93EF-1867D90FF1F5}

src/dotnet/CommonLocalizableStrings.resx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -520,28 +520,26 @@
520520
<data name="NoRestoreDescription" xml:space="preserve">
521521
<value>Does not do an implicit restore when executing the command.</value>
522522
</data>
523-
<data name="CannotBeNullOrWhitespace" xml:space="preserve">
524-
<value>Cannot be null or whitespace.</value>
525-
</data>
526-
<data name="ContainInvalidCharacters" xml:space="preserve">
527-
<value>Contains one or more invalid characters: {0}</value>
528-
</data>
529523
<data name="NuGetConfigurationFileDoesNotExist" xml:space="preserve">
530524
<value>NuGet configuration file {0} does not exist.</value>
531525
</data>
532-
<data name="ToolSettingInvalidRunner" xml:space="preserve">
533-
<value>The tool's settings file has non "dotnet" as runner.</value>
526+
<data name="ToolSettingsInvalidXml" xml:space="preserve">
527+
<value>Invalid XML: {0}</value>
528+
</data>
529+
<data name="ToolSettingsMissingCommandName" xml:space="preserve">
530+
<value>Tool defines a command with a missing name setting.</value>
534531
</data>
535-
<data name="ToolSettingMoreThanOneCommand" xml:space="preserve">
536-
<value>The tool's settings file has more than one command defined.</value>
532+
<data name="ToolSettingsMissingEntryPoint" xml:space="preserve">
533+
<value>Command '{0}' is missing an entry point setting.</value>
537534
</data>
538-
<data name="ToolSettingsContainError" xml:space="preserve">
539-
<value>The tool's settings file contains error.
540-
{0}</value>
535+
<data name="ToolSettingsInvalidCommandName" xml:space="preserve">
536+
<value>Command '{0}' contains one or more of the following invalid characters: {1}.</value>
541537
</data>
542-
<data name="ToolSettingsInvalidXml" xml:space="preserve">
543-
<value>The tool's settings file is invalid xml.
544-
{0}</value>
538+
<data name="ToolSettingsMoreThanOneCommand" xml:space="preserve">
539+
<value>More than one command is defined for the tool.</value>
540+
</data>
541+
<data name="ToolSettingsUnsupportedRunner" xml:space="preserve">
542+
<value>Command '{0}' uses unsupported runner '{1}'."</value>
545543
</data>
546544
<data name="EnvironmentPathLinuxManualInstruction" xml:space="preserve">
547545
<value>Cannot find the tools executable path. Please ensure {0} is added to your PATH.

src/dotnet/ToolPackage/IProjectRestorer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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+
using System.Collections.Generic;
45
using Microsoft.Extensions.EnvironmentAbstractions;
56

67
namespace Microsoft.DotNet.ToolPackage
@@ -11,6 +12,7 @@ void Restore(
1112
FilePath projectPath,
1213
DirectoryPath assetJsonOutput,
1314
FilePath? nugetconfig,
14-
string source);
15+
string source,
16+
string verbosity);
1517
}
1618
}

src/dotnet/ToolPackage/IToolPackageObtainer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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+
using System.Collections.Generic;
45
using Microsoft.Extensions.EnvironmentAbstractions;
56

67
namespace Microsoft.DotNet.ToolPackage
@@ -12,6 +13,7 @@ ToolConfigurationAndExecutablePath ObtainAndReturnExecutablePath(
1213
string packageVersion = null,
1314
FilePath? nugetconfig = null,
1415
string targetframework = null,
15-
string source = null);
16+
string source = null,
17+
string verbosity = null);
1618
}
1719
}

src/dotnet/ToolPackage/ToolConfiguration.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Linq;
67
using Microsoft.DotNet.Tools;
78

89
namespace Microsoft.DotNet.ToolPackage
@@ -15,33 +16,36 @@ public ToolConfiguration(
1516
{
1617
if (string.IsNullOrWhiteSpace(commandName))
1718
{
18-
throw new ArgumentNullException(nameof(commandName), CommonLocalizableStrings.CannotBeNullOrWhitespace);
19+
throw new ToolConfigurationException(CommonLocalizableStrings.ToolSettingsMissingCommandName);
1920
}
2021

21-
EnsureNoInvalidFilenameCharacters(commandName, nameof(toolAssemblyEntryPoint));
22-
2322
if (string.IsNullOrWhiteSpace(toolAssemblyEntryPoint))
2423
{
25-
throw new ArgumentNullException(nameof(toolAssemblyEntryPoint), CommonLocalizableStrings.CannotBeNullOrWhitespace);
24+
throw new ToolConfigurationException(
25+
string.Format(
26+
CommonLocalizableStrings.ToolSettingsMissingEntryPoint,
27+
commandName));
2628
}
2729

30+
EnsureNoInvalidFilenameCharacters(commandName);
31+
2832
CommandName = commandName;
2933
ToolAssemblyEntryPoint = toolAssemblyEntryPoint;
3034
}
3135

32-
private void EnsureNoInvalidFilenameCharacters(string commandName, string nameOfParam)
36+
private void EnsureNoInvalidFilenameCharacters(string commandName)
3337
{
34-
char[] invalidCharactors = Path.GetInvalidFileNameChars();
35-
if (commandName.IndexOfAny(invalidCharactors) != -1)
38+
var invalidCharacters = Path.GetInvalidFileNameChars();
39+
if (commandName.IndexOfAny(invalidCharacters) != -1)
3640
{
37-
throw new ArgumentException(
38-
paramName: nameof(nameOfParam),
39-
message: string.Format(CommonLocalizableStrings.ContainInvalidCharacters,
40-
new string(invalidCharactors)));
41+
throw new ToolConfigurationException(
42+
string.Format(
43+
CommonLocalizableStrings.ToolSettingsInvalidCommandName,
44+
commandName,
45+
string.Join(", ", invalidCharacters.Select(c => $"'{c}'"))));
4146
}
4247
}
4348

44-
4549
public string CommandName { get; }
4650
public string ToolAssemblyEntryPoint { get; }
4751
}

src/dotnet/ToolPackage/ToolConfigurationDeserializer.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,29 @@ public static ToolConfiguration Deserialize(string pathToXml)
2929
catch (InvalidOperationException e) when (e.InnerException is XmlException)
3030
{
3131
throw new ToolConfigurationException(
32-
string.Format(CommonLocalizableStrings.ToolSettingsInvalidXml, e.InnerException.Message));
32+
string.Format(
33+
CommonLocalizableStrings.ToolSettingsInvalidXml,
34+
e.InnerException.Message));
3335
}
3436
}
3537

3638
if (dotNetCliTool.Commands.Length != 1)
3739
{
38-
throw new ToolConfigurationException(
39-
CommonLocalizableStrings.ToolSettingMoreThanOneCommand);
40+
throw new ToolConfigurationException(CommonLocalizableStrings.ToolSettingsMoreThanOneCommand);
4041
}
4142

4243
if (dotNetCliTool.Commands[0].Runner != "dotnet")
4344
{
4445
throw new ToolConfigurationException(
45-
CommonLocalizableStrings.ToolSettingInvalidRunner);
46+
string.Format(
47+
CommonLocalizableStrings.ToolSettingsUnsupportedRunner,
48+
dotNetCliTool.Commands[0].Name,
49+
dotNetCliTool.Commands[0].Runner));
4650
}
4751

48-
var commandName = dotNetCliTool.Commands[0].Name;
49-
var toolAssemblyEntryPoint = dotNetCliTool.Commands[0].EntryPoint;
50-
51-
try
52-
{
53-
return new ToolConfiguration(commandName, toolAssemblyEntryPoint);
54-
}
55-
catch (ArgumentException e)
56-
{
57-
throw new ToolConfigurationException(
58-
string.Format(CommonLocalizableStrings.ToolSettingsContainError,
59-
e.Message));
60-
}
52+
return new ToolConfiguration(
53+
dotNetCliTool.Commands[0].Name,
54+
dotNetCliTool.Commands[0].EntryPoint);
6155
}
6256
}
6357
}

src/dotnet/ToolPackage/ToolPackageObtainer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
24
using System.IO;
35
using System.Linq;
46
using System.Xml.Linq;
@@ -38,7 +40,8 @@ public ToolConfigurationAndExecutablePath ObtainAndReturnExecutablePath(
3840
string packageVersion = null,
3941
FilePath? nugetconfig = null,
4042
string targetframework = null,
41-
string source = null)
43+
string source = null,
44+
string verbosity = null)
4245
{
4346
if (packageId == null)
4447
{
@@ -71,7 +74,7 @@ public ToolConfigurationAndExecutablePath ObtainAndReturnExecutablePath(
7174
targetframework,
7275
toolDirectory);
7376

74-
_projectRestorer.Restore(tempProjectPath, toolDirectory, nugetconfig, source);
77+
_projectRestorer.Restore(tempProjectPath, toolDirectory, nugetconfig, source, verbosity);
7578

7679
if (packageVersionOrPlaceHolder.IsPlaceholder)
7780
{

0 commit comments

Comments
 (0)