From 91714f5807f909b3a1c6be7cc0f799455efed682 Mon Sep 17 00:00:00 2001 From: Misha Gorshenin Date: Sun, 28 Apr 2024 23:42:30 +0500 Subject: [PATCH] feat: CLI: add /no-restore arg and SelfContained propeprty support --- src/ElectronNET.CLI/Commands/BuildCommand.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ElectronNET.CLI/Commands/BuildCommand.cs b/src/ElectronNET.CLI/Commands/BuildCommand.cs index 2f4f52c7..6ccf4aca 100644 --- a/src/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/src/ElectronNET.CLI/Commands/BuildCommand.cs @@ -15,6 +15,7 @@ public class BuildCommand : ICommand " for custom target, check .NET Core RID Catalog and Electron build target/" + Environment.NewLine + " e.g. '/target win' or '/target custom \"win7-x86;win\"'" + Environment.NewLine + "Optional: '/dotnet-configuration' with the desired .NET Core build config e.g. release or debug. Default = Release" + Environment.NewLine + + "Optional: '/no-restore' to disable nuget packages restore" + Environment.NewLine + "Optional: '/electron-arch' to specify the resulting electron processor architecture (e.g. ia86 for x86 builds). Be aware to use the '/target custom' param as well!" + Environment.NewLine + "Optional: '/electron-params' specify any other valid parameter, which will be routed to the electron-packager." + Environment.NewLine + "Optional: '/relative-path' to specify output a subdirectory for output." + Environment.NewLine + @@ -45,6 +46,8 @@ public BuildCommand(string[] args) private string _manifest = "manifest"; private string _paramPublishReadyToRun = "PublishReadyToRun"; private string _paramPublishSingleFile = "PublishSingleFile"; + private string _paramSelfContained = "SelfContained"; + private string _paramNoRestore = "no-restore"; private string _paramVersion = "Version"; public Task ExecuteAsync() @@ -81,6 +84,10 @@ public Task ExecuteAsync() configuration = parser.Arguments[_paramDotNetConfig][0]; } + string noRestore = parser.Arguments.ContainsKey(_paramNoRestore) + ? " --no-restore" + : string.Empty; + var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom); Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}..."); @@ -107,7 +114,7 @@ public Task ExecuteAsync() var dotNetPublishFlags = GetDotNetPublishFlags(parser); var command = - $"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))} --self-contained"; + $"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\"{noRestore} --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))}"; // output the command Console.ForegroundColor = ConsoleColor.Green; @@ -212,6 +219,7 @@ private Dictionary GetDotNetPublishFlags(SimpleCommandLineParser { {"/p:PublishReadyToRun", parser.TryGet(_paramPublishReadyToRun, out var rtr) ? rtr[0] : "true"}, {"/p:PublishSingleFile", parser.TryGet(_paramPublishSingleFile, out var psf) ? psf[0] : "true"}, + {"/p:SelfContained", parser.TryGet(_paramSelfContained, out var sc) ? sc[0] : "true"}, }; if (parser.Arguments.ContainsKey(_paramVersion))