运行 通过批处理文件的 VS 代码项目

Run VS code projects through batch file

我有很多项目需要在 windows 启动期间打开。

所以我创建了批处理文件以在 vs 代码中打开它们,如下所示。

start cmd /C code C:\project1

start cmd /C code C:\Project2

start cmd /C code C:\ProjectN

我也需要他们运行。每个项目我都有 launch.json。如何通过批处理文件执行它们。

首先,我建议按如下方式精简您的批处理文件

for %%p in (C:\project1 C:\project2 C:\projectN) do code %%p

每个项目将在其自己的 window 中异步打开 - 不需要 start,也不需要 cmd 子进程(double-quote 需要的单独路径).

  • 注意:如果您想使用单个工作空间在一个单个window中打开所有项目,您只需执行以下操作:

    code C:\project1 C:\project2 C:\projectN
    

至于您希望在打开启动调试的项目,看来codeVisual Studio's CLI 支持这个,至少从 v1.66 开始是这样。

这并不奇怪,因为 editor/IDE 的重点是 编辑 代码,而不是 运行 它。

从 v1.66 开始,code -h 报告以下选项(也记录在上面的 link 中):

C:\>code -h

Visual Studio Code 1.66.0

Usage: code [options][paths...]

To read from stdin, append '-' (e.g. 'ps aux | grep code | code -')

Options
  -d --diff <file> <file>           Compare two files with each other.
  -a --add <folder>                 Add folder(s) to the last active window.
  -g --goto <file:line[:character]> Open a file at the path on the specified
                                    line and character position.
  -n --new-window                   Force to open a new window.
  -r --reuse-window                 Force to open a file or folder in an
                                    already opened window.
  -w --wait                         Wait for the files to be closed before
                                    returning.
  --locale <locale>                 The locale to use (e.g. en-US or zh-TW).
  --user-data-dir <dir>             Specifies the directory that user data is
                                    kept in. Can be used to open multiple
                                    distinct instances of Code.
  -h --help                         Print usage.

Extensions Management
  --extensions-dir <dir>              Set the root path for extensions.
  --list-extensions                   List the installed extensions.
  --show-versions                     Show versions of installed extensions,
                                      when using --list-extensions.
  --category <category>               Filters installed extensions by provided
                                      category, when using --list-extensions.
  --install-extension <ext-id | path> Installs or updates an extension. The
                                      argument is either an extension id or a
                                      path to a VSIX. The identifier of an
                                      extension is '${publisher}.${name}'. Use
                                      '--force' argument to update to latest
                                      version. To install a specific version
                                      provide '@${version}'. For example:
                                      'vscode.csharp@1.2.3'.
  --pre-release                       Installs the pre-release version of the
                                      extension, when using
                                      --install-extension
  --uninstall-extension <ext-id>      Uninstalls an extension.
  --enable-proposed-api <ext-id>      Enables proposed API features for
                                      extensions. Can receive one or more
                                      extension IDs to enable individually.

Troubleshooting
  -v --version                    Print version.
  --verbose                       Print verbose output (implies --wait).
  --log <level>                   Log level to use. Default is 'info'. Allowed
                                  values are 'critical', 'error', 'warn',
                                  'info', 'debug', 'trace', 'off'.
  -s --status                     Print process usage and diagnostics
                                  information.
  --prof-startup                  Run CPU profiler during startup.
  --disable-extensions            Disable all installed extensions.
  --disable-extension <ext-id>    Disable an extension.
  --sync <on | off>               Turn sync on or off.
  --inspect-extensions <port>     Allow debugging and profiling of extensions.
                                  Check the developer tools for the connection
                                  URI.
  --inspect-brk-extensions <port> Allow debugging and profiling of extensions
                                  with the extension host being paused after
                                  start. Check the developer tools for the
                                  connection URI.
  --disable-gpu                   Disable GPU hardware acceleration.
  --max-memory <memory>           Max memory size for a window (in Mbytes).
  --telemetry                     Shows all telemetry events which VS code
                                  collects.

本来想运行一气呵成所有项目的。认为 vs 代码通过 multi-root 工作区提供了此类功能(您还可以使用此 multi-root 工作区在一个地方检查所有 git 更改)。

我们可以 运行 使用下面的工作区定义一次性完成所有项目,其中配置是您需要在文件夹内的 vs 代码中启动的所有 launch.json name

"compounds": [{
      "name": "Launch Server & Client",
      "configurations": [
        "Launch Server",
        {
          "folder": "Web Client",
          "name": "Launch Client"
        },
        {
          "folder": "Desktop Client",
          "name": "Launch Client"
        }
      ]
  }]

来源:https://code.visualstudio.com/docs/editor/multi-root-workspaces