【问题标题】:Run Multiple VS code projects through batch file (in a single go)通过批处理文件运行多个 VS 代码项目(一次)
【发布时间】:2022-07-22 03:02:46
【问题描述】:

在 Windows 启动期间,我必须打开很多项目。

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

start cmd /C code C:\project1

start cmd /C code C:\Project2

start cmd /C code C:\ProjectN

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

【问题讨论】:

    标签: powershell batch-file visual-studio-code automation


    【解决方案1】:

    首先,我建议精简你的批处理文件如下:

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

    每个项目将在自己的窗口中异步打开 - 不需要start,也不需要cmd 子进程(根据需要双引号单独的路径)。

    • 注意:如果您想在一个单个窗口中使用单个工作区打开所有项目,您可以简单地执行以下操作:

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

    至于你希望启动项目打开后调试,看来code,Visual Studio's CLI 支持这个,至少从 v1.66 开始。

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

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

    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.
    

    【讨论】:

      【解决方案2】:

      最初我想一次性运行所有项目。认为 vs code 通过多根工作区提供了这样的功能(您还可以使用这个多根工作区在一个地方检查所有 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

      【讨论】:

        猜你喜欢
        • 2019-05-17
        • 1970-01-01
        • 1970-01-01
        • 2013-01-11
        • 1970-01-01
        • 1970-01-01
        • 2012-12-18
        • 2017-10-10
        • 1970-01-01
        相关资源
        最近更新 更多