diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs index f7416256f0e0..5fea6df78ae1 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs +++ b/src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs @@ -2,11 +2,18 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.DotNet.Cli.Utils; +using NuGet.Configuration; namespace Microsoft.DotNet.Tools.Common { public static class PathUtility { + public static bool CheckForNuGetInNuGetConfig() + { + var otherFiles = SettingsUtility.GetEnabledSources(Settings.LoadDefaultSettings(Directory.GetCurrentDirectory())); + return otherFiles.Any(source => source.SourceUri.Equals("https://api.nuget.org/v3/index.json")); + } + public static bool IsPlaceholderFile(string path) { return string.Equals(Path.GetFileName(path), "_._", StringComparison.Ordinal); diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/NuGet/NugetApiManager.cs b/src/Cli/Microsoft.TemplateEngine.Cli/NuGet/NugetApiManager.cs index a714e9783ef7..969b769a1924 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/NuGet/NugetApiManager.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/NuGet/NugetApiManager.cs @@ -34,10 +34,14 @@ internal NugetApiManager() PackageSource? sourceFeed = null, CancellationToken cancellationToken = default) { - if (sourceFeed == null) + if (sourceFeed == null && Microsoft.DotNet.Tools.Common.PathUtility.CheckForNuGetInNuGetConfig()) { sourceFeed = _nugetOrgSource; } + else if (sourceFeed is null) + { + return null; + } SourceRepository repository = GetSourceRepository(sourceFeed); PackageMetadataResource resource = await repository.GetResourceAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs b/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs index 313a7fd31501..b4dda2fd7a46 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs @@ -3,6 +3,7 @@ using System.CommandLine; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Tools.Common; using Microsoft.TemplateEngine.Abstractions; using Microsoft.TemplateEngine.Abstractions.Constraints; using Microsoft.TemplateEngine.Abstractions.Installer; @@ -436,7 +437,7 @@ internal async Task DisplayTemplatePackageMetadata( } else { - IEnumerable packageSources = LoadNuGetSources(additionalSources, true); + IEnumerable packageSources = LoadNuGetSources(additionalSources, includeNuGetFeed: PathUtility.CheckForNuGetInNuGetConfig()); nuGetPackageMetadata = await GetPackageMetadataFromMultipleFeedsAsync(packageSources, nugetApiManager, packageIdentity, packageVersion, cancellationToken).ConfigureAwait(false); if (nuGetPackageMetadata != null && nuGetPackageMetadata.Source.Source.Equals(NugetOrgFeed)) diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-tool/search/LocalizableStrings.resx index 4811e1f5339a..386ea6140aa3 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/LocalizableStrings.resx +++ b/src/Cli/dotnet/commands/dotnet-tool/search/LocalizableStrings.resx @@ -196,4 +196,10 @@ Version Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + \ No newline at end of file diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/ToolSearchCommand.cs b/src/Cli/dotnet/commands/dotnet-tool/search/ToolSearchCommand.cs index d6daf44c568f..29d9c4a75d27 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/ToolSearchCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-tool/search/ToolSearchCommand.cs @@ -5,6 +5,8 @@ using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.NugetSearch; +using Microsoft.DotNet.Tools.Common; +using NuGet.Configuration; namespace Microsoft.DotNet.Tools.Tool.Search { @@ -26,6 +28,12 @@ public ToolSearchCommand( public override int Execute() { var isDetailed = _parseResult.GetValue(ToolSearchCommandParser.DetailOption); + if (!PathUtility.CheckForNuGetInNuGetConfig()) + { + Reporter.Output.WriteLine(LocalizableStrings.NeedNuGetInConfig); + return 0; + } + NugetSearchApiParameter nugetSearchApiParameter = new(_parseResult); IReadOnlyCollection searchResultPackages = NugetSearchApiResultDeserializer.Deserialize( diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.cs.xlf index c7df98b9f33e..8735c705a192 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.cs.xlf @@ -47,6 +47,15 @@ Nejnovější verze Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. Nenašly se žádné výsledky. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.de.xlf index f50e42d103d3..e2a2fb2c47e9 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.de.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.de.xlf @@ -47,6 +47,15 @@ Aktuelle Version Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. Es wurden keine Ergebnisse gefunden. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.es.xlf index b8e9fef63dc9..8912b64e886e 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.es.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.es.xlf @@ -47,6 +47,15 @@ Última versión Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. No se encontró ningún resultado. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.fr.xlf index c97a6615044d..adf9625fdc88 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.fr.xlf @@ -47,6 +47,15 @@ Dernière version Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. Résultats introuvables. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.it.xlf index a3709cb177d1..ca389bb04a5b 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.it.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.it.xlf @@ -47,6 +47,15 @@ Ultima versione Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. Non è stato possibile trovare risultati. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ja.xlf index 46bdcad7a907..59c7f632178f 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ja.xlf @@ -47,6 +47,15 @@ 最新バージョン Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. 結果が見つかりませんでした。 diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ko.xlf index 8ebc31feffed..e3f997df3bd3 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ko.xlf @@ -47,6 +47,15 @@ 최신 버전 Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. 결과를 찾을 수 없습니다. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.pl.xlf index 8f00f81eb056..87564f82fde7 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.pl.xlf @@ -47,6 +47,15 @@ Najnowsza wersja Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. Nie można znaleźć żadnych wyników. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.pt-BR.xlf index 9f4434a65b52..2367aeb40b37 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.pt-BR.xlf @@ -47,6 +47,15 @@ Última Versão Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. Não foi possível localizar nenhum resultado. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ru.xlf index 89719b96d5de..1cb904fa5f8c 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.ru.xlf @@ -47,6 +47,15 @@ Последняя версия Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. Ничего не найдено. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.tr.xlf index cdbe99b97a8e..fca2bd8d4de3 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.tr.xlf @@ -47,6 +47,15 @@ En Son Sürüm Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. Sonuç bulunamadı. diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.zh-Hans.xlf index d90034d3dfcb..bf04ef763834 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.zh-Hans.xlf @@ -47,6 +47,15 @@ 最新版本 Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. 找不到任何结果。 diff --git a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.zh-Hant.xlf index 274dd5b10281..9fda02783409 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/commands/dotnet-tool/search/xlf/LocalizableStrings.zh-Hant.xlf @@ -47,6 +47,15 @@ 最新版本 Table lable + + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + The 'dotnet tool search' command unconditionally accesses nuget.org to find tools, but it is not present in your nuget.config. Add it to run this command. + This can be done with this command: + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org + Do not translate 'dotnet tool search' or 'nuget.config'. Do not localize the last line at all. + Could not find any results. 找不到任何結果。 diff --git a/test/dotnet-new.Tests/DotnetNewDetailsTest.Approval.cs b/test/dotnet-new.Tests/DotnetNewDetailsTest.Approval.cs index 25e9d00d8b5c..89698d8e9bf2 100644 --- a/test/dotnet-new.Tests/DotnetNewDetailsTest.Approval.cs +++ b/test/dotnet-new.Tests/DotnetNewDetailsTest.Approval.cs @@ -31,14 +31,27 @@ public Task CanDisplayDetails_RemotePackage_NuGetFeedWithVersion() [Fact] public Task CanDisplayDetails_RemotePackage_NuGetFeedNoVersion() { - CommandResult commandResult = new DotnetNewCommand(_log, "details", _nuGetPackageId) - .WithCustomHive(CreateTemporaryFolder(folderName: "Home")) - .WithWorkingDirectory(CreateTemporaryFolder()) + var folder = CreateTemporaryFolder(); + + var createCommandResult = () => new DotnetNewCommand(_log, "details", _nuGetPackageId) + .WithCustomHive(CreateTemporaryFolder(folderName: "Home")) + .WithWorkingDirectory(folder) .Execute(); - commandResult - .Should() - .Pass(); + createCommandResult().Should().Fail(); + + File.WriteAllText(Path.Combine(folder, "NuGet.Config"), @" + + + + + + +"); + + var commandResult = createCommandResult(); + + commandResult.Should().Pass(); return Verify(commandResult.StdOut); }