Skip to content

Commit 00768c6

Browse files
authored
dotnet tool install --local works by default, by creating a manifest by default, utilizing --create-manifest-if-needed (#48906)
2 parents 00b42e5 + 2543536 commit 00768c6

40 files changed

+127
-323
lines changed

src/Cli/dotnet/CliStrings.resx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ The default is 'false.' However, when targeting .NET 7 or lower, the default is
577577
<value>outputpathresolver: {0} does not exist</value>
578578
</data>
579579
<data name="CannotFindAManifestFile" xml:space="preserve">
580-
<value>Cannot find a manifest file.
581-
For a list of locations searched, specify the "-d" option before the tool name.</value>
580+
<value>Cannot find a manifest file. The list of searched paths:
581+
{0}</value>
582582
</data>
583583
<data name="CannotFindPackageIdInManifest" xml:space="preserve">
584584
<value>Cannot find a package with the package id {0} in the manifest file.</value>
@@ -670,10 +670,6 @@ For a list of locations searched, specify the "-d" option before the tool name.<
670670
<data name="LibraryNotFoundInLockFile" xml:space="preserve">
671671
<value>{0}: library not found in lock file.</value>
672672
</data>
673-
<data name="ListOfSearched" xml:space="preserve">
674-
<value>The list of searched paths:
675-
{0}</value>
676-
</data>
677673
<data name="LookingForPreferCliRuntimeFile" xml:space="preserve">
678674
<value>{0}: Looking for prefercliruntime file at `{1}`</value>
679675
</data>

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,10 +1975,6 @@ Tool '{1}' (version '{2}') was successfully installed.</value>
19751975
<data name="ToolInstallManifestPathOptionName" xml:space="preserve">
19761976
<value>PATH</value>
19771977
</data>
1978-
<data name="ToolInstallNoManifestGuide" xml:space="preserve">
1979-
<value>If you intended to install a global tool, add `--global` to the command.
1980-
If you would like to create a manifest, use the `--create-manifest-if-needed` flag with the `dotnet tool install` command, or use `dotnet new tool-manifest`, usually in the repo root directory.</value>
1981-
</data>
19821978
<data name="ToolInstallNuGetConfigurationFileDoesNotExist" xml:space="preserve">
19831979
<value>NuGet configuration file '{0}' does not exist.</value>
19841980
</data>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ internal static class ToolInstallCommandParser
4949
public static readonly Option<bool> CreateManifestIfNeededOption = new("--create-manifest-if-needed")
5050
{
5151
Description = CliCommandStrings.CreateManifestIfNeededOptionDescription,
52-
Arity = ArgumentArity.Zero
52+
Arity = ArgumentArity.ZeroOrOne,
53+
DefaultValueFactory = _ => true,
5354
};
5455

5556
public static readonly Option<bool> AllowPackageDowngradeOption = new("--allow-downgrade")

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,8 @@ public int InstallNewTool(FilePath manifestFile, PackageId packageId)
194194

195195
public FilePath GetManifestFilePath()
196196
{
197-
try
198-
{
199-
return string.IsNullOrWhiteSpace(_explicitManifestFile)
200-
? _toolManifestFinder.FindFirst(_createManifestIfNeeded)
201-
: new FilePath(_explicitManifestFile);
202-
}
203-
catch (ToolManifestCannotBeFoundException e)
204-
{
205-
throw new GracefulException(
206-
[e.Message, CliCommandStrings.ToolInstallNoManifestGuide],
207-
verboseMessages: [e.VerboseMessage],
208-
isUserError: false);
209-
}
197+
return string.IsNullOrWhiteSpace(_explicitManifestFile)
198+
? _toolManifestFinder.FindFirst(_createManifestIfNeeded)
199+
: new FilePath(_explicitManifestFile);
210200
}
211201
}

src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/ToolManifest/ToolManifestCannotBeFoundException.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,4 @@ internal class ToolManifestCannotBeFoundException : GracefulException
1212
public ToolManifestCannotBeFoundException(string message) : base([message], null, false)
1313
{
1414
}
15-
16-
public ToolManifestCannotBeFoundException(string message, string optionalMessage)
17-
: base([message], [optionalMessage], false)
18-
{
19-
}
2015
}

src/Cli/dotnet/ToolManifest/ToolManifestFinder.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ public IReadOnlyCollection<ToolManifestPackage> Find(FilePath? filePath = null)
4141

4242
if (!findAnyManifest)
4343
{
44-
throw new ToolManifestCannotBeFoundException(
45-
CliStrings.CannotFindAManifestFile,
46-
string.Format(CliStrings.ListOfSearched,
47-
string.Join(Environment.NewLine, allPossibleManifests.Select(f => "\t" + f.manifestfile.Value))));
44+
throw new ToolManifestCannotBeFoundException(string.Format(CliStrings.CannotFindAManifestFile, string.Join(Environment.NewLine, allPossibleManifests.Select(f => "\t" + f.manifestfile.Value))));
4845
}
4946

5047
return [.. toolManifestPackageAndSource.Select(t => t.toolManifestPackage)];
@@ -182,11 +179,7 @@ public FilePath FindFirst(bool createIfNotFound = false)
182179
return new FilePath(WriteManifestFile(manifestInsertFolder));
183180
}
184181
}
185-
throw new ToolManifestCannotBeFoundException(
186-
CliStrings.CannotFindAManifestFile,
187-
string.Format(CliStrings.ListOfSearched,
188-
string.Join(Environment.NewLine,
189-
EnumerateDefaultAllPossibleManifests().Select(f => "\t" + f.manifestfile.Value))));
182+
throw new ToolManifestCannotBeFoundException(string.Format(CliStrings.CannotFindAManifestFile, string.Join(Environment.NewLine, EnumerateDefaultAllPossibleManifests().Select(f => "\t" + f.manifestfile.Value))));
190183
}
191184

192185
/*
@@ -274,11 +267,7 @@ in EnumerateDefaultAllPossibleManifests())
274267

275268
if (!findAnyManifest)
276269
{
277-
throw new ToolManifestCannotBeFoundException(
278-
CliStrings.CannotFindAManifestFile,
279-
string.Format(CliStrings.ListOfSearched,
280-
string.Join(Environment.NewLine,
281-
EnumerateDefaultAllPossibleManifests().Select(f => "\t" + f.manifestfile.Value))));
270+
throw new ToolManifestCannotBeFoundException(string.Format(CliStrings.CannotFindAManifestFile, string.Join(Environment.NewLine, EnumerateDefaultAllPossibleManifests().Select(f => "\t" + f.manifestfile.Value))));
282271
}
283272

284273
return result;

0 commit comments

Comments
 (0)