我需要把我安装的所有扩展发给我的同事。我如何导出它们?

扩展管理器似乎什么也不做…它不会安装任何扩展。


当前回答

在windows下,我通常需要运行

cd C:\Program Files\Microsoft VS Code\bin
code.cmd --list-extensions

你不做的是运行Code .exe直接在C:\Program Files\Microsoft VS Code\

其他回答

我使用下面的命令将我的扩展从Visual Studio Code复制到Visual Studio Code内部:

code --list-extensions | xargs -L 1 code-insiders --install-extension

参数- l1允许我们对由code——list-extensions生成的每个输入行执行一次命令code-insiders——install-extension。

生成用于安装扩展的Windows命令文件(批处理):

for /F "tokens=*" %i in ('code --list-extensions')
   do @echo call code --install-extension %i >> install.cmd

在Windows上,使用powershell脚本。这将返回一个更好地反映名字的“FriendlyName”,因为它将出现在Visual Studio Code UI中(这是Code -list-extensions所不做的):

<#
.SYNOPSIS 
    Lists installed Visual Studio Code Extensions in a friendly format.

.DESCRIPTION
    Lists installed Visual Studio Code Extensions in a friendly format.
    
.INPUTS
    None. You cannot pipe objects to this.

.OUTPUTS
    A list of installed Visual Studio Code Extensions in a friendly format.

.EXAMPLE
    PS> .\List-Extensions.ps1  

.NOTES
  Author: John Bentley
  Version: 2022-07-11 18:55
  Latest at: [How can you export the Visual Studio Code extension list?
              > John Bentley's Answer]
            (https://stackoverflow.com/a/72929878/872154)
#>

# Change to your directory
$packages = Get-ChildItem C:/Users/John/.vscode/extensions/*/package.json 

Function Out-JsonItem($File) { 
  $json = Get-Content $File | ConvertFrom-Json 
  $extensionMetaData = [PSCustomObject]@{

    # This is the name that appears in the Visual Studio Code UI, 
    # Extensions Tab
    FriendlyName = 
      if ($json.displayName) { $json.displayName } else { $json.name }
      
    # Name = $json.name
    PublisherAndName = $json.publisher + '.' + $json.name

    Description = $json.description
  }
  return $extensionMetaData
}

$extensions = ($packages | ForEach-Object { Out-JsonItem -File $_ }) 

$extensions.GetEnumerator() | Sort-Object {$_.FriendlyName} 

# Alternate sorting (Same order as `code --list-extensions`). 
# $extensions.GetEnumerator() | Sort-Object {$_.PublisherAndName} 

示例输出:

FriendlyName                             PublisherAndName
------------                             ----------------
[Deprecated] Debugger for Chrome         msjsdiag.debugger-for-chrome
%displayName%                            ms-vscode-remote.remote-wsl
Apache Conf                              mrmlnc.vscode-apache
Apache Conf Snippets                     eiminsasete.apacheconf-snippets
Auto Close Tag                           formulahendry.auto-close-tag
Beautify                                 HookyQR.beautify
Blank Line Organizer                     rintoj.blank-line-organizer
change-case                              wmaurer.change-case
Character Count                          stevensona.character-count
...
Word Count                               ms-vscode.wordcount
Word Count                               OliverKovacs.word-count
XML                                      redhat.vscode-xml
XML Tools                                DotJoshJohnson.xml
XML Tools                                qub.qub-xml-vscode
XPath Notebook for Visual Studio Code    deltaxml.xpath-notebook
XSLT/XPath for Visual Studio Code        deltaxml.xslt-xpath 

产品说明:

复制脚本代码并将其保存为List-Extensions文件。ps1某处(仅限Windows)。 修改$packages = Get-ChildItem C:/Users/John/.vscode/extensions/*/package。Json指向您的目录(更改用户名)。 在你保存List-Extensions的目录下打开Windows终端。ps1(这里的Set-Location命令可能有帮助)。 使用。\List-Extensions.ps1从Windows终端运行脚本

我打开Visual Studio Code扩展文件夹并执行:

find * -maxdepth 2 -name "package.json" | xargs grep "name"

这将为您提供一个列表,您可以从中提取扩展名。

Windows (PowerShell)版本的本尼的答案

机:

在Visual Studio Code PowerShell终端中:

代码:> extensions.list

机器B:

复制扩展。解析:选B 在Visual Studio Code PowerShell终端中: 猫的扩展。列出|% {code——install-extension $_}