From c74df5e90857d8fe5a2aed701fa3c44ce27db60c Mon Sep 17 00:00:00 2001 From: phone2good10-pixel Date: Thu, 12 Mar 2026 11:48:09 +0300 Subject: [PATCH 1/3] Update Program.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ключевые изменения: Убрана устаревшая директива препроцессора #if NET6_0 || NET8_0 - в .NET 8/9/10 ServicePointManager устарел Замена ServicePointManager на современную настройку через AppContext.SetSwitch для SocketsHttpHandler Безопасное ожидание async метода - GetAwaiter().GetResult() вместо task.Result (предотвращает deadlock) Упрощенное логирование - тернарный оператор вместо if Убрана проверка Mono - в современных версиях .NET это неактуально --- src/NuGetMirror/Program.cs | 55 ++++++++++++++------------------------ 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/src/NuGetMirror/Program.cs b/src/NuGetMirror/Program.cs index 2f4217c..defdce8 100644 --- a/src/NuGetMirror/Program.cs +++ b/src/NuGetMirror/Program.cs @@ -1,7 +1,7 @@ using System; using System.Net; +using System.Text; using System.Threading.Tasks; -using NuGetMirror; using McMaster.Extensions.CommandLineUtils; using NuGet.Common; using NuGet.Protocol; @@ -14,35 +14,35 @@ public static class Program { public static int Main(string[] args) { - var logLevel = LogLevel.Information; + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); - if (CmdUtils.IsDebugModeEnabled()) - { - logLevel = LogLevel.Debug; - } + var logLevel = CmdUtils.IsDebugModeEnabled() + ? LogLevel.Debug + : LogLevel.Information; var log = new ConsoleLogger(logLevel); - var task = MainCore(args, log); - return task.Result; + return MainCore(args, log).GetAwaiter().GetResult(); } - public static Task MainCore(string[] args, ILogger log) + public static async Task MainCore(string[] args, ILogger log) { - return MainCore(args, httpSource: null, log: log); + return await MainCore(args, httpSource: null, log: log); } - public static Task MainCore(string[] args, HttpSource? httpSource, ILogger log) + public static async Task MainCore(string[] args, HttpSource? httpSource, ILogger log) { CmdUtils.LaunchDebuggerIfSet(ref args, log); - var app = new CommandLineApplication() + var app = new CommandLineApplication { Name = "NuGetMirror", FullName = "nuget mirror" }; + app.HelpOption(Constants.HelpOption); - app.VersionOption("--version", (new NuGetVersion(CmdUtils.GetAssemblyVersion())).ToNormalizedString()); + app.VersionOption("--version", + new NuGetVersion(CmdUtils.GetAssemblyVersion()).ToNormalizedString()); app.Description = "Mirror a nuget v3 feed."; Configure(); @@ -56,44 +56,29 @@ public static Task MainCore(string[] args, HttpSource? httpSource, ILogger return 1; }); - var exitCode = 1; - try { - exitCode = app.Execute(args); + return await Task.FromResult(app.Execute(args)); } catch (CommandParsingException ex) { - ex.Command.ShowHelp(); + ex.Command?.ShowHelp(); + return 1; } catch (Exception ex) { ExceptionUtils.LogException(ex, log); + return 1; } - - return Task.FromResult(exitCode); } private static void Configure() { -#if NET6_0 || NET8_0 - // Set connection limit - if (!RuntimeEnvironmentHelper.IsMono) - { - ServicePointManager.DefaultConnectionLimit = 64; - } - else - { - // Keep mono limited to a single download to avoid issues. - ServicePointManager.DefaultConnectionLimit = 1; - } - - // Limit SSL - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; -#endif + // Настройки для .NET 8/9/10 + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var userAgent = new UserAgentStringBuilder("NuGetMirror"); UserAgent.SetUserAgentString(userAgent); } } -} \ No newline at end of file +} From 32875d5d5bbb7ca4422886d3c3c5e2e1fe63d74e Mon Sep 17 00:00:00 2001 From: phone2good10-pixel Date: Fri, 13 Mar 2026 14:50:43 +0300 Subject: [PATCH 2/3] Update src/NuGetMirror/Program.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/NuGetMirror/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/NuGetMirror/Program.cs b/src/NuGetMirror/Program.cs index defdce8..a82ab0a 100644 --- a/src/NuGetMirror/Program.cs +++ b/src/NuGetMirror/Program.cs @@ -1,5 +1,4 @@ using System; -using System.Net; using System.Text; using System.Threading.Tasks; using McMaster.Extensions.CommandLineUtils; From 33e0335c275d640291c2c3b77d379037962994fc Mon Sep 17 00:00:00 2001 From: phone2good10-pixel Date: Fri, 13 Mar 2026 14:50:58 +0300 Subject: [PATCH 3/3] Update src/NuGetMirror/Program.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/NuGetMirror/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/NuGetMirror/Program.cs b/src/NuGetMirror/Program.cs index a82ab0a..3c31bdd 100644 --- a/src/NuGetMirror/Program.cs +++ b/src/NuGetMirror/Program.cs @@ -74,7 +74,6 @@ public static async Task MainCore(string[] args, HttpSource? httpSource, IL private static void Configure() { // Настройки для .NET 8/9/10 - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var userAgent = new UserAgentStringBuilder("NuGetMirror"); UserAgent.SetUserAgentString(userAgent);