--- /dev/null
+using System;
+using System.Runtime.InteropServices;
+class RestartExample {
+#if NET5_0_OR_GREATER
+ public static void Restart() {
+ System.Console.WriteLine("Core!");
+ // Use ProcessStartInfo.ArgumentList to pass args
+ Environment.Exit(0);
+ }
+#else
+ // Technically an unsafe API but we keep it private
+ [DllImport("KERNEL32.dll", ExactSpelling=true, SetLastError=true)]
+ private static extern int CreateProcessW(
+ string lpApplicationName,
+ char[] lpCommandLine,
+ IntPtr lpProcesAttributes,
+ IntPtr lpThreadAttributes,
+ int bInheritHandles,
+ uint dwCreationFlags,
+ IntPtr lpEnvironment,
+ string lpCurrentDirectory,
+ IntPtr lpStartupInfo,
+ IntPtr lpProcessInformation
+ );
+ public static void Restart() {
+ Console.WriteLine("Windows!");
+ char[] lpCommandLine = Environment.CommandLine.ToCharArray();
+ // Use CreateProcessW with lpCommandLine to relaunch process
+ Environment.Exit(0);
+ }
+#endif
+
+ public static void Main(string[] args) {
+ Restart();
+ }
+}
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">\r
+\r
+ <PropertyGroup>\r
+ <OutputType>Exe</OutputType>\r
+ <TargetFrameworks>net11.0;net45</TargetFrameworks>\r
+ </PropertyGroup>\r
+\r
+</Project>\r