How to install Visual Studio Code extensions from Command line

前端 未结 5 1731
时光说笑
时光说笑 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 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    
    }
    

提交回复
热议问题