How to install Visual Studio Code extensions from Command line

前端 未结 5 1724
时光说笑
时光说笑 2021-01-30 06:41

How to install Visual Studio Code Extensions from Command Prompt while Code Instance is open. I want to install extension from Visual Studio Code gallery.

Following is th

相关标签:
5条回答
  • 2021-01-30 06:59

    To make it easier to automate and configure VS Code, it is possible to list, install, and uninstall extensions from the command line. When identifying an extension, provide the full name of the form publisher.extension, for example donjayamanne.python.

    code --list-extensions
    code --install-extension ms-vscode.cpptools
    code --uninstall-extension ms-vscode.csharp
    

    Documentation

    0 讨论(0)
  • 2021-01-30 06:59

    To add to Shan Khan's answer above, if you want to install extensions in a .bat file, you have to use the call keyword, otherwise your script exits after the extension installation completes. Also, if code.exe is not already in the path and you are calling using a full path, make sure you're pointing at the /bin directory:

    echo.
    echo.
    echo Installing VS Code Extensions...
    call "C:\Program Files\Microsoft VS Code\bin\code" --install-extension ritwickdey.liveserver
    call "C:\Program Files\Microsoft VS Code\bin\code" --install-extension ritwickdey.live-sass
    call "C:\Program Files\Microsoft VS Code\bin\code" --install-extension ms-vscode.csharp
    call "C:\Program Files\Microsoft VS Code\bin\code" --install-extension PKief.material-icon-theme
    echo Done.
    echo.
    echo.
    
    0 讨论(0)
  • 2021-01-30 07:02

    First, find the fully qualified extension name. To do this, you can right-click a given extension, and select 'Copy Extension Id' (while in the extensions pane).

    Since the other answers already illustrate .BAT/.CMD syntax, here's an example of installing extensions using a Powershell script (which can of course be executed from CMD).

    # A system-wide install of VSCode might be in: "C:\Program Files\Microsoft VS Code\bin\code"
    param(
        [string] $pathToVsCodeExe = ($Env:USERPROFILE + '\AppData\Local\Programs\Microsoft VS Code'),
        [string[]] $extensions = @("editorconfig.editorconfig", "dbaeumer.vscode-eslint")
    )
    
    
    try {
        $originalLocation = Get-Location
        Set-Location $pathToVsCodeExe
        $extensions | ForEach-Object {
            Invoke-Expression -Command "Code --install-extension $_ --force"
        }    
    }
    catch {
        $_
    }
    finally {
        Set-Location $originalLocation    
    }
    
    0 讨论(0)
  • 2021-01-30 07:08

    According to the documentation, you can use --install-extension for that. For example:

    code --install-extension ms-vscode.csharp
    
    0 讨论(0)
  • 2021-01-30 07:10

    I believe what you want is to install an extension as .vsix file. Documentation here. Copied for reference.

    You can manually install an VS Code extension packaged in a .vsix file. Simply install using the VS Code command line providing the path to the .vsix file.

    code --install-extension myExtensionFolder\myExtension.vsix

    The extension will be installed under your user .vscode/extensions folder. You may provide multiple .vsix files on the command line to install multiple extensions at once.

    0 讨论(0)
提交回复
热议问题