I have the following .NET (Core) 6 code to open a folder in VS Code in Windows (my app doesn't need to run on other environments):
public void OpenInVsCode()
{
Console.WriteLine("Opening folder in VS Code: " + this.Folder);
var procInfo = new ProcessStartInfo("code.exe", this.Folder)
{
// These 3 lines don't seem to matter
RedirectStandardOutput = false,
RedirectStandardInput = false,
RedirectStandardError = false,
// This line should solve the problem but it doesn't
UseShellExecute = true,
};
Process.Start(procInfo);
}
VS Code does start. However it starts printing its output into my console app and when my Console app closes, VS Code is closed as well, which seems contradicting to this answer.
How do I start a totally separated Process?
Update: It seems strange that in my Console app if it ends by itself (i.e. reaches to the last line), the app stops and will not close VS Code even if I close the finished Console window. However if the app stays open (due to Console.ReadLine
or await Task.Delay
) and I close it by closing the Console window or pressing Ctrl + C, VS Code is terminated.