diff --git a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs
index a12d4275..14962640 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
@@ -27,6 +28,19 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
netCorePublishRid = "osx-x64";
electronPackerPlatform = "mac";
break;
+ 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";
electronPackerPlatform = "linux";
@@ -48,8 +62,20 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
- netCorePublishRid = "osx-x64";
- electronPackerPlatform = "mac";
+ 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";
+ }
+ else{
+ //Intel Mac:
+ netCorePublishRid = "osx-x64";
+ electronPackerPlatform = "mac";
+ }
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
@@ -66,5 +92,42 @@ 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:
+ //execute dotnet --list-sdks to get versions
+ 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;
+
+ //get command output:
+ while ((standard_output = process.StandardOutput.ReadLine()) != null)
+ {
+ //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;
+ }
+ }
+ process.WaitForExit();
+ return dotnet6Exists;
+ }
}
-}
+}
\ No newline at end of file
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];
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: