mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-22 23:15:25 +00:00
Add dotnet 6 check
Ensure that dotnet 6 is installed when compiling for MacOS ARM.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ElectronNET.CLI.Commands.Actions
|
||||
@@ -30,6 +31,15 @@ namespace ElectronNET.CLI.Commands.Actions
|
||||
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 @@ namespace ElectronNET.CLI.Commands.Actions
|
||||
}
|
||||
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 @@ namespace ElectronNET.CLI.Commands.Actions
|
||||
NetCorePublishRid = netCorePublishRid
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Returns true if dotnet 6 or greater is installed.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user