通过批处理文件运行多个VS代码项目(一次性)



我有很多项目必须在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

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

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

    code C:project1 C:project2 C:projectN
    

至于您希望在打开后启动项目进行调试,似乎code,Visual Studio的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.

最初我想一口气运行所有项目。认为vs代码通过多根工作区提供了这样的功能(您还可以使用这个多根工作空间在一个地方检查所有git更改(。

我们可以通过下面的工作区定义一次性运行所有项目,其中configurations只不过是单个launch.json文件的name字段,您需要在子文件夹/项目内的代码中启动该字段(如果多个launch.json中的name相同,则您需要指定foldername。更多详细信息请参阅下面的链接。(

并将此工作区放置在所有子项目的根目录下。打开这个工作区并点击F5,它将一次性运行所有项目(已经说过,您在下面的工作区中提到的每个项目都有单独的launch.json文件(。

"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

最新更新