From 4790c4ebb2b6e2baa706cc47b3e0c6d72e4aab34 Mon Sep 17 00:00:00 2001 From: Daniel Gidman Date: Fri, 21 Jan 2022 16:51:30 -0600 Subject: [PATCH 1/2] Support for additional dotnet publish flags. --- ElectronNET.CLI/Commands/BuildCommand.cs | 52 +++++++++++++++++++++++- README.md | 15 +++++++ 2 files changed, 66 insertions(+), 1 deletion(-) mode change 100644 => 100755 ElectronNET.CLI/Commands/BuildCommand.cs diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs old mode 100644 new mode 100755 index d9c0746..87b6a17 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -23,6 +23,9 @@ namespace ElectronNET.CLI.Commands "Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine + "Optional: '/Version' to specify the version that should be applied to both the `dotnet publish` and `electron-builder` commands. Implied by '/Version'" + Environment.NewLine + "Optional: '/p:[property]' or '/property:[property]' to pass in dotnet publish properties. Example: '/property:Version=1.0.0' to override the FileVersion" + Environment.NewLine + + "Optional: '-- [-a|--arch ] [-f | --framework] [--force] [--no-dependencies] [--no-incremental] [--no-restore] [--nologo]" + Environment.NewLine + + " [--no-self-contained] [--os ] [--self-contained [true|false]] [--source ] [-v|--verbosity ] [--version-suffix ]'" + Environment.NewLine + + " to add additional dot net publish arguments." + Environment.NewLine + "Full example for a 32bit debug build with electron prune: build /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--prune=true \""; public static IList CommandOptions { get; set; } = new List(); @@ -107,8 +110,15 @@ namespace ElectronNET.CLI.Commands 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}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))}"; + // add any additional dotnet flags + var dotnetFlags = GetDotNetArgs(_args); + if (dotnetFlags.Any()) + { + command += " " + string.Join(" ", dotnetFlags); + } + // output the command Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(command); @@ -206,6 +216,46 @@ namespace ElectronNET.CLI.Commands }); } + private static List DotNetFlagsWithValuesReserved = new List + { + "-o", "--output", "-r", "--runtime", "-c", "--configuration" + }; + private static List DotNetFlagsToIgnore = new List + { + "--interactive", "-h", "--help" + }; + private List GetDotNetArgs(string[] args) + { + if (!args.Contains("--")) return new List { "--self-contained" }; + + var list = args + .SkipWhile(i => "--".Equals(i, StringComparison.OrdinalIgnoreCase)) + .Skip(1) + .Except(DotNetFlagsToIgnore) + .ToList(); + + // ensure the args flag is removed + list.Remove("--"); + + // remove flags that are handled by design + foreach (var flag in DotNetFlagsWithValuesReserved) + { + var f = list.IndexOf(flag); + if (f > -1) + { + list.RemoveRange(f, 2); + } + } + + // enforce backwards compatibility + if (!list.Contains("--no-self-contained") && !list.Contains("--self-contained")) + { + list.Add("--self-contained"); + } + + return list; + } + private Dictionary GetDotNetPublishFlags(SimpleCommandLineParser parser) { var dotNetPublishFlags = new Dictionary diff --git a/README.md b/README.md index e6e1533..6b4a0d5 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,21 @@ For certain NuGet packages or certain scenarios you may want to build a pure x86 electronize build /target custom "win7-x86;win32" /electron-arch ia32 ``` +### Additional DotNet Publish Flags + +For certain scenarios additional `dotnet publish` arguments may be required. To add additional publish flags use the `--` flag at the end of your command and add any additional publish flags after. For example if you want to skip the default nuget restore you can do that like this: + +``` +electronize build /target osx -- --no-restore +``` + +#### Self-Contained +> `--self-contained` is enabled by default, to disable use `--no-self-contained` or `--self-contained false` + +#### Ignored Flags +> `-r|--runtime`, `-o|--output`, `-c|--configuration`, `--interactive` & `-h|--help` are ignored by design + + The end result should be an electron app under your __/bin/desktop__ folder. ### Note From 5338749e4d2b0fcd9c46bad1a61e5c7d7d0f18cc Mon Sep 17 00:00:00 2001 From: Daniel Gidman Date: Fri, 21 Jan 2022 20:03:31 -0600 Subject: [PATCH 2/2] Fixed extraction of arguments --- ElectronNET.CLI/Commands/BuildCommand.cs | 14 +++++--------- README.md | 4 ++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index 87b6a17..2cc04dc 100755 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -23,7 +23,7 @@ namespace ElectronNET.CLI.Commands "Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine + "Optional: '/Version' to specify the version that should be applied to both the `dotnet publish` and `electron-builder` commands. Implied by '/Version'" + Environment.NewLine + "Optional: '/p:[property]' or '/property:[property]' to pass in dotnet publish properties. Example: '/property:Version=1.0.0' to override the FileVersion" + Environment.NewLine + - "Optional: '-- [-a|--arch ] [-f | --framework] [--force] [--no-dependencies] [--no-incremental] [--no-restore] [--nologo]" + Environment.NewLine + + "Optional: '/dotnet-publish [-a|--arch ] [-f | --framework] [--force] [--no-dependencies] [--no-incremental] [--no-restore] [--nologo]" + Environment.NewLine + " [--no-self-contained] [--os ] [--self-contained [true|false]] [--source ] [-v|--verbosity ] [--version-suffix ]'" + Environment.NewLine + " to add additional dot net publish arguments." + Environment.NewLine + "Full example for a 32bit debug build with electron prune: build /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--prune=true \""; @@ -49,6 +49,7 @@ namespace ElectronNET.CLI.Commands private string _paramPublishReadyToRun = "PublishReadyToRun"; private string _paramPublishSingleFile = "PublishSingleFile"; private string _paramVersion = "Version"; + private string _paramDotNetPublish = "dotnet-publish"; public Task ExecuteAsync() { @@ -113,7 +114,7 @@ namespace ElectronNET.CLI.Commands $"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))}"; // add any additional dotnet flags - var dotnetFlags = GetDotNetArgs(_args); + var dotnetFlags = GetDotNetArgs(parser); if (dotnetFlags.Any()) { command += " " + string.Join(" ", dotnetFlags); @@ -224,19 +225,14 @@ namespace ElectronNET.CLI.Commands { "--interactive", "-h", "--help" }; - private List GetDotNetArgs(string[] args) + private List GetDotNetArgs(SimpleCommandLineParser parser) { - if (!args.Contains("--")) return new List { "--self-contained" }; + if (!parser.TryGet(_paramDotNetPublish, out var args)) return new List { "--self-contained" }; var list = args - .SkipWhile(i => "--".Equals(i, StringComparison.OrdinalIgnoreCase)) - .Skip(1) .Except(DotNetFlagsToIgnore) .ToList(); - // ensure the args flag is removed - list.Remove("--"); - // remove flags that are handled by design foreach (var flag in DotNetFlagsWithValuesReserved) { diff --git a/README.md b/README.md index 6b4a0d5..3971039 100644 --- a/README.md +++ b/README.md @@ -150,10 +150,10 @@ electronize build /target custom "win7-x86;win32" /electron-arch ia32 ### Additional DotNet Publish Flags -For certain scenarios additional `dotnet publish` arguments may be required. To add additional publish flags use the `--` flag at the end of your command and add any additional publish flags after. For example if you want to skip the default nuget restore you can do that like this: +For certain scenarios additional `dotnet publish` arguments may be required. To add additional publish flags use the `/dotnet-publish` flag and add any additional publish flags after. For example if you want to skip the default nuget restore you can do that like this: ``` -electronize build /target osx -- --no-restore +electronize build /target osx /dotnet-publish --no-restore ``` #### Self-Contained