From 438c8e1f1408bb3d26362672ad0f237752d5ab3c Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Sat, 20 Nov 2021 17:56:33 -0500 Subject: [PATCH 1/9] Switch from dotnet 5.0 to dotnet 6.0 The 'osx-arm64' RID is only supported on .net versions greater than 6.0. https://docs.microsoft.com/en-us/dotnet/core/rid-catalog --- ElectronNET.CLI/ElectronNET.CLI.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj index a4bd0118..ff012858 100644 --- a/ElectronNET.CLI/ElectronNET.CLI.csproj +++ b/ElectronNET.CLI/ElectronNET.CLI.csproj @@ -3,7 +3,7 @@ Exe - net5.0 + net6.0 dotnet-electronize electronize @@ -33,7 +33,7 @@ - AnyCPU + 4 From 5dbe62bcba7f2cb979f413209dc4e97a5069d738 Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Sat, 20 Nov 2021 17:59:53 -0500 Subject: [PATCH 2/9] Add osx-arm64 support to electronize command Updates the GetTargetPlatformInformationResult() function to add 'osx-arm64' target. Updates the 'default' case to automatically detect M1 mac. --- .../Actions/GetTargetPlatformInformation.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs index a12d4275..159a44d6 100644 --- a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs +++ b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs @@ -27,6 +27,10 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri netCorePublishRid = "osx-x64"; electronPackerPlatform = "mac"; break; + case "osx-arm64": + netCorePublishRid = "osx-arm64"; + electronPackerPlatform = "darwin-arm64"; + break; case "linux": netCorePublishRid = "linux-x64"; electronPackerPlatform = "linux"; @@ -48,8 +52,17 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - netCorePublishRid = "osx-x64"; - electronPackerPlatform = "mac"; + if (RuntimeInformation.OSArchitecture.Equals(Architecture.Arm64)) + { + //Apple Silicon Mac: + netCorePublishRid = "osx-arm64"; + electronPackerPlatform = "darwin-arm64"; + } + else{ + //Intel Mac: + netCorePublishRid = "osx-x64"; + electronPackerPlatform = "mac"; + } } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { From 07d6fed71267f9a06bd45e254eff3145f8ee270f Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Sat, 20 Nov 2021 18:24:41 -0500 Subject: [PATCH 3/9] Fix for build command --- .../Commands/Actions/GetTargetPlatformInformation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs index 159a44d6..020110b6 100644 --- a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs +++ b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs @@ -29,7 +29,7 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri break; case "osx-arm64": netCorePublishRid = "osx-arm64"; - electronPackerPlatform = "darwin-arm64"; + electronPackerPlatform = "mac"; break; case "linux": netCorePublishRid = "linux-x64"; @@ -56,7 +56,7 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri { //Apple Silicon Mac: netCorePublishRid = "osx-arm64"; - electronPackerPlatform = "darwin-arm64"; + electronPackerPlatform = "mac"; } else{ //Intel Mac: From 4ba8d9bf46fa58a3e19637c692139f0dd7d71939 Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Sat, 20 Nov 2021 18:25:46 -0500 Subject: [PATCH 4/9] Add fix for Apple Silicon to build command --- ElectronNET.CLI/Commands/BuildCommand.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index d9c07465..56d002ba 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -170,7 +170,13 @@ public Task ExecuteAsync() Console.WriteLine("Executing electron magic in this directory: " + buildPath); + string electronArch = "x64"; + //Somewhat janky fix for Apple Silicon: + if (platformInfo.NetCorePublishRid == "osx-arm64") + { + electronArch = "arm64"; + } if (parser.Arguments.ContainsKey(_paramElectronArch)) { electronArch = parser.Arguments[_paramElectronArch][0]; From e0e8572cc119e75355d270a26e1b5959768cb38f Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Sat, 20 Nov 2021 21:35:02 -0500 Subject: [PATCH 5/9] Update README.md Add notes about osx-arm64. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6e1533a..2f1d4041 100644 --- a/README.md +++ b/README.md @@ -137,10 +137,13 @@ There are additional platforms available: ``` electronize build /target win electronize build /target osx +electronize build /target osx-arm64 electronize build /target linux ``` -Those three "default" targets will produce x64 packages for those platforms. +Those four "default" targets will produce packages for those platforms. + +Note that the `osx-arm64` build requires that the project target `net6.0`. `osx-arm64` is for Apple Silicon Macs. For certain NuGet packages or certain scenarios you may want to build a pure x86 application. To support those things you can define the desired [.NET Core runtime](https://docs.microsoft.com/en-us/dotnet/core/rid-catalog), the [electron platform](https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#platform) and [electron architecture](https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#arch) like this: From 1d9e540fc2e26c3f0ccfb43cd11c58e8da9ec159 Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Mon, 6 Dec 2021 20:17:08 -0500 Subject: [PATCH 6/9] Change back to dotnet 5 --- ElectronNET.CLI/ElectronNET.CLI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj index ff012858..a1829ced 100644 --- a/ElectronNET.CLI/ElectronNET.CLI.csproj +++ b/ElectronNET.CLI/ElectronNET.CLI.csproj @@ -3,7 +3,7 @@ Exe - net6.0 + net5.0 dotnet-electronize electronize From e4deba2489b83723a06d41dc9f90140cf8a614c1 Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Mon, 6 Dec 2021 20:17:46 -0500 Subject: [PATCH 7/9] Add dotnet 6 check Ensure that dotnet 6 is installed when compiling for MacOS ARM. --- .../Actions/GetTargetPlatformInformation.cs | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs index 020110b6..af0561de 100644 --- a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs +++ b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Runtime.InteropServices; namespace ElectronNET.CLI.Commands.Actions @@ -30,6 +31,15 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri case "osx-arm64": netCorePublishRid = "osx-arm64"; electronPackerPlatform = "mac"; + + //Check to see if .net 6 is installed: + if (!Dotnet6Installed()) + { + throw new ArgumentException("You are using a dotnet version older than dotnet 6. Compiling for osx-arm64 requires that dotnet 6 or greater is installed and targeted by your project.", "osx-arm64"); + } + + //Warn for .net 6 targeting: + Console.WriteLine("Please ensure that your project targets .net 6 or greater. Otherwise you may experience an error compiling for osx-arm64."); break; case "linux": netCorePublishRid = "linux-x64"; @@ -52,8 +62,11 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - if (RuntimeInformation.OSArchitecture.Equals(Architecture.Arm64)) + if (RuntimeInformation.OSArchitecture.Equals(Architecture.Arm64) && Dotnet6Installed()) { + //Warn for .net 6 targeting: + Console.WriteLine("Please ensure that your project targets .net 6. Otherwise you may experience an error."); + //Apple Silicon Mac: netCorePublishRid = "osx-arm64"; electronPackerPlatform = "mac"; @@ -79,5 +92,37 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri NetCorePublishRid = netCorePublishRid }; } + /// + /// Checks to see if dotnet 6 or greater is installed. + /// Required for MacOS arm targeting. + /// Note that an error may still occur if the project being compiled does not target dotnet 6 or greater. + /// + /// + /// Returns true if dotnet 6 or greater is installed. + /// + private static bool Dotnet6Installed() + { + //check for .net 6: + Process process = new Process(); + process.StartInfo.FileName = "dotnet"; + process.StartInfo.Arguments = "--list-sdks"; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.Start(); + + string standard_output; + bool dotnet6Exists = false; + while ((standard_output = process.StandardOutput.ReadLine()) != null) + { + if (standard_output.StartsWith("6.")) + { + dotnet6Exists = true; + break; + } + } + process.WaitForExit(); + return dotnet6Exists; + } } -} +} \ No newline at end of file From 7e89e27c2685948daf574bce91a72934cbe436d7 Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Mon, 6 Dec 2021 20:28:57 -0500 Subject: [PATCH 8/9] Better way to check version Checks to see if the dotnet 6 or greater is running. --- .../Commands/Actions/GetTargetPlatformInformation.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs index af0561de..14962640 100644 --- a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs +++ b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs @@ -103,6 +103,7 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri private static bool Dotnet6Installed() { //check for .net 6: + //execute dotnet --list-sdks to get versions Process process = new Process(); process.StartInfo.FileName = "dotnet"; process.StartInfo.Arguments = "--list-sdks"; @@ -113,9 +114,13 @@ private static bool Dotnet6Installed() string standard_output; bool dotnet6Exists = false; + + //get command output: while ((standard_output = process.StandardOutput.ReadLine()) != null) { - if (standard_output.StartsWith("6.")) + //get the major version and see if its greater than or equal to 6 + int majorVer = int.Parse(standard_output.Split(".")[0]); + if (majorVer >= 6) { dotnet6Exists = true; break; From b08a0755e6810fb1c95e7972f58e937f91e01f20 Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Tue, 7 Dec 2021 12:23:26 -0500 Subject: [PATCH 9/9] Revert automatic change by VS --- ElectronNET.CLI/ElectronNET.CLI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj index a1829ced..a4bd0118 100644 --- a/ElectronNET.CLI/ElectronNET.CLI.csproj +++ b/ElectronNET.CLI/ElectronNET.CLI.csproj @@ -33,7 +33,7 @@ - 4 + AnyCPU