powershell - 通过批处理文件运行多个 VS Code 项目(一次)

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

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

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

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

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

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

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

至于您希望在打开后启动项目进行调试,似乎代码, 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:
                                      '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a0c0919151e1f541909121b080a3a4b54485449" rel="noreferrer noopener nofollow">[email protected]</a>'.
  --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.

关于powershell - 通过批处理文件运行多个 VS Code 项目(一次),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71727475/

相关文章:

powershell - 如何将参数传递给 Powershell 脚本并在远程计算机上运行它

visual-studio-code - 如何在 VS Code 的更改 View 中交换不同的 Pane ?

typescript - Visual Studio 代码 :[js] types can only be used in a . ts 文件

visual-studio-code - 如何在 vscode 中打开文件夹选择器对话框?

powershell - 如何使用 powershell 在文件中的特定行之后插入文本?

用于过滤具有多个值的记录的 PowerShell 命令

powershell - 将标题添加到已有数据的 .csv 列

sql - 如何使用批处理文件运行多个SQL脚本?

windows - 使用任务计划程序通过自动屏幕捕获获取空白(黑色)屏幕截图

batch-file - 使用批处理文件执行 msbuild 项目