以编程方式启动 Visual Studio Code

Mik*_*ews 1 .net c# .net-core

我正在尝试在 C# 中以编程方式启动 VS Code。

我需要类似的东西

System.Diagnostics.Process.Start("notepad.exe", "test.txt");
Run Code Online (Sandbox Code Playgroud)

如果它可以在 Windows、MacOS 和 Linux 上运行,那是理想的选择,但主要是 Windows。

我试图启动一个名为“code”的进程,因为你只需输入codecmd 提示符或运行,它就会启动 VS Code,但无法找到一种方法来做到这一点。

小智 6

我之前写过一些调用 VS Code 的东西:

public static class ProcessHelper
{
    public static void Open(string app, string args)
    {
        using (Process myProcess = new Process())
        {
            myProcess.StartInfo.UseShellExecute = true;
            myProcess.StartInfo.FileName = app;
            myProcess.StartInfo.Arguments = args;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start();
        }
    }

    public static void OpenVsCode(string filePath)
    {
        Open("code", filePath);
    }
}
Run Code Online (Sandbox Code Playgroud)

所以你可以这样使用它:

ProcessHelper.OpenVsCode("c:\\myfile.txt");
Run Code Online (Sandbox Code Playgroud)