Skip to content

Commit e4deba2

Browse files
committed
Add dotnet 6 check
Ensure that dotnet 6 is installed when compiling for MacOS ARM.
1 parent 1d9e540 commit e4deba2

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Runtime.InteropServices;
34

45
namespace ElectronNET.CLI.Commands.Actions
@@ -30,6 +31,15 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
3031
case "osx-arm64":
3132
netCorePublishRid = "osx-arm64";
3233
electronPackerPlatform = "mac";
34+
35+
//Check to see if .net 6 is installed:
36+
if (!Dotnet6Installed())
37+
{
38+
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");
39+
}
40+
41+
//Warn for .net 6 targeting:
42+
Console.WriteLine("Please ensure that your project targets .net 6 or greater. Otherwise you may experience an error compiling for osx-arm64.");
3343
break;
3444
case "linux":
3545
netCorePublishRid = "linux-x64";
@@ -52,8 +62,11 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
5262
}
5363
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
5464
{
55-
if (RuntimeInformation.OSArchitecture.Equals(Architecture.Arm64))
65+
if (RuntimeInformation.OSArchitecture.Equals(Architecture.Arm64) && Dotnet6Installed())
5666
{
67+
//Warn for .net 6 targeting:
68+
Console.WriteLine("Please ensure that your project targets .net 6. Otherwise you may experience an error.");
69+
5770
//Apple Silicon Mac:
5871
netCorePublishRid = "osx-arm64";
5972
electronPackerPlatform = "mac";
@@ -79,5 +92,37 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
7992
NetCorePublishRid = netCorePublishRid
8093
};
8194
}
95+
/// <summary>
96+
/// Checks to see if dotnet 6 or greater is installed.
97+
/// Required for MacOS arm targeting.
98+
/// Note that an error may still occur if the project being compiled does not target dotnet 6 or greater.
99+
/// </summary>
100+
/// <returns>
101+
/// Returns true if dotnet 6 or greater is installed.
102+
/// </returns>
103+
private static bool Dotnet6Installed()
104+
{
105+
//check for .net 6:
106+
Process process = new Process();
107+
process.StartInfo.FileName = "dotnet";
108+
process.StartInfo.Arguments = "--list-sdks";
109+
process.StartInfo.UseShellExecute = false;
110+
process.StartInfo.RedirectStandardOutput = true;
111+
process.StartInfo.RedirectStandardError = true;
112+
process.Start();
113+
114+
string standard_output;
115+
bool dotnet6Exists = false;
116+
while ((standard_output = process.StandardOutput.ReadLine()) != null)
117+
{
118+
if (standard_output.StartsWith("6."))
119+
{
120+
dotnet6Exists = true;
121+
break;
122+
}
123+
}
124+
process.WaitForExit();
125+
return dotnet6Exists;
126+
}
82127
}
83-
}
128+
}

0 commit comments

Comments
 (0)