From b5e69f5dda0c3fef23132f2577a440c4e6dfbfd1 Mon Sep 17 00:00:00 2001 From: tub5 Date: Thu, 4 Mar 2021 14:45:52 +0000 Subject: [PATCH 1/2] Fixes Add ability to pass an argument for "Version" for both the "dotnet publish" and "electron-builder" commands #543 --- ElectronNET.CLI/Commands/BuildCommand.cs | 21 ++++++++++++++++++--- ElectronNET.Host/build-helper.js | 3 +++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index 8117446a..32d31719 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -1,4 +1,5 @@ -using System; +BuildCommand.cs +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -21,6 +22,7 @@ public class BuildCommand : ICommand "Optional: '/absolute-path to specify and absolute path for output." + Environment.NewLine + "Optional: '/package-json' to specify a custom package.json file." + Environment.NewLine + "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 + "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(); @@ -43,6 +45,7 @@ public BuildCommand(string[] args) private string _manifest = "manifest"; private string _paramPublishReadyToRun = "PublishReadyToRun"; private string _paramPublishSingleFile = "PublishSingleFile"; + private string _paramVersion = "Version"; public Task ExecuteAsync() { @@ -53,6 +56,11 @@ public Task ExecuteAsync() SimpleCommandLineParser parser = new SimpleCommandLineParser(); parser.Parse(_args); + //This version will be shared between the dotnet publish and electron-builder commands + string version = null; + if (parser.Arguments.ContainsKey(_paramVersion)) + version = parser.Arguments[_paramVersion][0]; + if (!parser.Arguments.ContainsKey(_paramTarget)) { Console.WriteLine($"Error: missing '{_paramTarget}' argument."); @@ -116,7 +124,11 @@ public Task ExecuteAsync() publishSingleFile += "true"; } - var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} {publishSingleFile} --self-contained", Directory.GetCurrentDirectory()); + var dotNetVersionArguments = !string.IsNullOrWhiteSpace(version) + ? $"/p:Version={version}" + : ""; + + var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" {dotNetVersionArguments} --output \"{tempBinPath}\" {publishReadyToRun} {publishSingleFile} --self-contained", Directory.GetCurrentDirectory()); if (resultCode != 0) { @@ -194,7 +206,10 @@ public Task ExecuteAsync() manifestFileName = parser.Arguments[_manifest].First(); } - ProcessHelper.CmdExecute($"node build-helper.js " + manifestFileName, tempPath); + ProcessHelper.CmdExecute( + string.IsNullOrWhiteSpace(version) + ? $"node build-helper.js {manifestFileName}" + : $"node build-helper.js {manifestFileName} {version}", tempPath); Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}..."); ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=11.1.1 {electronParams}", tempPath); diff --git a/ElectronNET.Host/build-helper.js b/ElectronNET.Host/build-helper.js index e35ac160..d8ebc944 100644 --- a/ElectronNET.Host/build-helper.js +++ b/ElectronNET.Host/build-helper.js @@ -5,6 +5,9 @@ const dasherize = require('dasherize'); const fs = require('fs'); const builderConfiguration = { ...manifestFile.build }; +if(process.argv.length > 3) { + builderConfiguration.buildVersion = process.argv[3]; +} if(builderConfiguration.hasOwnProperty('buildVersion')) { // @ts-ignore const packageJson = require('./package'); From c94702fc60dfdecc640ba8dd6e6d630249ed3dfc Mon Sep 17 00:00:00 2001 From: tub5 Date: Mon, 28 Jun 2021 12:10:05 +0100 Subject: [PATCH 2/2] Remove incorrect text at the top of the file --- ElectronNET.CLI/Commands/BuildCommand.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index 32d31719..f9f5fdbd 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -1,5 +1,4 @@ -BuildCommand.cs -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq;