Anonymous Creator
Anonymous Creator

Reputation: 3819

Run Multiple VS code projects through batch file (in a single go)

I have so many projects I have to open during windows startup.

So I have created batch file to open them in vs code as following.

start cmd /C code C:\project1

start cmd /C code C:\Project2

start cmd /C code C:\ProjectN

I also need them to run. I have launch.json for each project. How do I execute them through batch file.

Upvotes: 2

Views: 850

Answers (2)

Anonymous Creator
Anonymous Creator

Reputation: 3819

Originally I wanted to run all the projects in one go. Figured that vs code provides such functionality through multi-root workspaces (You will be also able to check all git changes in one place using this multi-root workspace).

We can run all the projects in one go with the workspace definition below where configurations are nothing but individual launch.json file's name field which you need to launch in vs code which are inside sub folders/projects (if name are same in multiple launch.json then you need to specify folder along with name. More details in link below.)

And place this workspace at root of all child projects. Open this workspace and hit F5, it will run all the projects as well in single go (having said that you have individual launch.json files for each project which you have mentioned in below workspace).

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

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

Upvotes: 2

mklement0
mklement0

Reputation: 439597

First, I suggest streamlining your batch file as follows:

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

Each project will open in its own window, asynchronously - no need for start, and no need for cmd child processes (double-quote individual paths as needed).

  • Note: If you wanted to open all projects in a single window, using a single workspace, you could simply do:

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

As for your desire to launch the projects for debugging after opening, it seems that code, Visual Studio's CLI does not support this, at least as of v1.66.

This isn't too surprising, given that the focus of an editor/IDE is on editing code, not on running it.

As of v1.66, code -h reports the following options (as also documented in the link above):

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:
                                      '[email protected]'.
  --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.

Upvotes: 2

Related Questions