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

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


当前回答

其他答案需要发送一个文件,我认为这太繁琐了。如果您需要将所有扩展名发送到另一台计算机上安装,请使用以下方式列出您的扩展名:

code --list-extensions

你可以使用如下格式的单行命令安装多个扩展:

code --install-extension dakshmiglani.hex-to-rgba --install-extension techer.open-in-browser

一个简单的方法来格式化你的扩展列表来创建命令是做一个regex搜索和替换:

Paste your copied list into a new document and search for: (.+)(\n?) Replace with --install-extension $1 (Don't omit the space at the beginning.) Add the word code to the start of the resulting text and you'll have a very large command that you can hand off to your colleagues to run in their terminal. code --install-extension hbenl.vscode-test-explorer --install-extension maciejdems.add-to-gitignore --install-extension techer.open-in-browser --install-extension traBpUkciP.vscode-npm-scripts ...

其他回答

在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终端运行脚本

代码——扩展>列表 Sed -i 's/。*/\"&\",/' 列表 复制文件列表的内容并添加到文件.vscode/extensions。Json在“建议”部分。 如果扩展。Json不存在,然后用以下内容创建一个文件 { “建议”:[ //在这里添加文件列表内容 ] } 共享扩展。Json文件,并要求另一个用户添加到.vscode文件夹。Visual Studio Code将提示安装扩展。

如果您想将所有扩展从代码转移到代码内部人员,或者反之亦然,下面是我从Git Bash中获得的效果。

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

这将安装所有缺少的扩展,并跳过已安装的扩展。在此之后,您将需要关闭并重新打开Visual Studio Code。

类似地,您可以使用以下方法将扩展从代码内部转移到代码:

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

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

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

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

如果您打算跨团队共享工作空间扩展配置,您应该查看Visual Studio Code的推荐扩展特性。

要生成该文件,请打开命令托盘> Configure Recommended Extensions (Workspace Folder)。从那里,如果你想获得所有当前的扩展并将它们放在这里,你可以使用——list-extensions在其他答案中提到的东西,但添加一些AWK脚本,使其可粘贴到JSON数组中(你可以根据自己的需要获得更多或更少的高级功能-这只是一个快速示例):

代码——list-extensions | awk的{打印“\”“0”\“\”}”

这种方法的优点是可以将团队范围内的工作空间配置检入源代码控制。有了这个文件在项目中,当项目打开时,Visual Studio Code会通知用户有推荐的扩展需要安装(如果他们还没有的话),并且可以用一个按钮将它们全部安装。