I am developing a .NetCore Console Application that will be used on both Windows and MacOS. I have a requirement that the Console Application should not be visible to the end-user in any way.
I have achieved this on Windows by making use of kernel32 and user32 dll's:
[DllImport("kernel32.dll")]
private static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;
const int SW_SHOW = 5;
const int SW_RESTORE = 9;
public static void EnableBackgroundMode()
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE);
}
public static void DisableBackgroundMode()
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_SHOW);
}
When trying to use these methods on MacOS I get a 'System.DllNotFoundException', which is expected because these dll's are windows specific to my understanding.
Is there any way to achieve this on MacOS?