【vscode】解决vscode无法安装远程服务器插件问题,显示正在安装

文章目录

现状分析

vscode无法远程安装扩展插件,显示正在安装
现象 :一直处于这个正在安装状态

原因 :

服务器没网或者其他各种原因;

采用VSIX离线安装

第一步:离线下载插件包

vscode的扩展下载市场下载需要的插件Extensions for Visual Studio family of products | Visual Studio Marketplace

现在没办法下载VSIX了;

找到一个脚本可以下载VSCode插件:
GitHub - mjmirza/Download-VSIX-From-Visual-Studio-Market-Place: This script allows you to download VS Code extensions as VSIX files directly from the Visual Studio Marketplace.

这个脚本代码在这粘贴出来:

js 复制代码
/***
#          Download VS Code extensions as VSIX
#          Author: Mirza Iqbal
***/
 
// *** SCRIPTS NOT TESTED After July 2024 *** //
 
/***
// First 
***/
!function() {
    (function() {
        const extensionData = {
            version: "",
            publisher: "",
            identifier: "",
            getDownloadUrl: function() {
                return `https://${this.identifier.split(".")[0]}.gallery.vsassets.io/_apis/public/gallery/publisher/${this.identifier.split(".")[0]}/extension/${this.identifier.split(".")[1]}/${this.version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage`;
            },
            getFileName: function() {
                return `${this.identifier}_${this.version}.vsix`;
            },
            getDownloadButton: function() {
                const button = document.createElement("a");
                button.innerHTML = "Download VSIX";
                button.href = "javascript:void(0);";
                button.style.fontFamily = "wf_segoe-ui,Helvetica Neue,Helvetica,Arial,Verdana";
                button.style.display = "inline-block";
                button.style.padding = "2px 5px";
                button.style.background = "darkgreen";
                button.style.color = "white";
                button.style.fontWeight = "bold";
                button.style.margin = "2px 5px";
                button.setAttribute("data-url", this.getDownloadUrl());
                button.setAttribute("data-filename", this.getFileName());
 
                button.onclick = function(event) {
                    event.target.onclick = null;
                    event.target.innerHTML = "Downloading VSIX...";
                    const xhr = new XMLHttpRequest();
                    console.log(event.target.getAttribute("data-url"));
                    xhr.open("GET", event.target.getAttribute("data-url"), true);
                    xhr.responseType = "blob";
 
                    xhr.onprogress = function(event) {
                        if (event.lengthComputable) {
                            const progress = (event.loaded / event.total * 100).toFixed(0);
                            event.target.innerHTML = `Downloading VSIX... ${progress}%`;
                        }
                    };
 
                    xhr.onload = function() {
                        if (this.status === 200) {
                            const blob = this.response;
                            const link = document.createElement("a");
                            link.href = window.URL.createObjectURL(blob);
                            link.download = event.target.getAttribute("data-filename");
                            link.click();
                            event.target.href = link.href;
                            event.target.download = link.download;
                            event.target.innerHTML = "Download VSIX";
                        } else {
                            event.target.innerHTML = "Error. Please reload the page and try again.";
                            alert(`Error ${this.status} error receiving the document.`);
                        }
                    };
 
                    xhr.onerror = function() {
                        event.target.innerHTML = "Error. Please reload the page and try again.";
                        alert(`Error ${this.target.status} occurred while receiving the document.`);
                    };
 
                    xhr.send();
                };
 
                return button;
            }
        };
 
        const metadataMap = {
            Version: "version",
            Publisher: "publisher",
            "Unique Identifier": "identifier"
        };
 
        const metadataRows = document.querySelectorAll(".ux-table-metadata tr");
 
        for (let i = 0; i < metadataRows.length; i++) {
            const row = metadataRows[i];
            const cells = row.querySelectorAll("td");
            if (cells.length === 2) {
                const key = cells[0].innerText.trim();
                const value = cells[1].innerText.trim();
                if (metadataMap.hasOwnProperty(key)) {
                    extensionData[metadataMap[key]] = value;
                }
            }
        }
 
        // Handle the case where the element might not exist
        const moreInfoElement = document.querySelector(".vscode-moreinformation");
        if (moreInfoElement) {
            moreInfoElement.parentElement.appendChild(extensionData.getDownloadButton()).scrollIntoView();
        } else {
            console.error("Element with class 'vscode-moreinformation' not found.");
        }
    }
    )()
}();
 
 
/***
// 2nd 
***/
(function() {
    const URL_VSIX_PATTERN = 'https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${publisher}/vsextensions/${extension}/${version}/vspackage';
    const itemName = new URL(window.location.href).searchParams.get('itemName');
    const [publisher, extension] = itemName.split('.');
    const version = document.querySelector('#versionHistoryTab tbody tr .version-history-container-column').textContent;
    const url = URL_VSIX_PATTERN.replace('${publisher}', publisher).replace('${extension}', extension).replace('${version}', version);
    window.open(url, '_blank');
 
})();

脚本使用

  1. 先进入VSCode的插件市场:Extensions for Visual Studio family of products | Visual Studio Marketplace
  2. 找到你感兴趣的插件,比如CMake Tools,然后按F12键出现右边的开发者窗口。
  3. 在右下角控制台粘贴前面准备的代码,按下回车,浏览器就会自动下载
第二步:把下载好的插件文件上传到远程服务器上
第三步:在windows下打开vscode,并链接远端,进行安装

进入vscode选择扩展,选择右上角三个点的选项,选择VSIX安装。然后找到thirdpart目录下对应的插件文件选择即可。


此时显示已经安装成功 :

相关推荐
智购科技无人售货机工厂店2 小时前
自动售货机刷脸支付集成实战:活体检测与合规门槛~YH
java·服务器·前端·科技·零售
Mars-xq3 小时前
Android studio下载很慢download fail
android·ide·android studio
开开心心就好3 小时前
定时结束进程的小工具,到点还能关机
linux·运维·服务器·智能手机·pdf·电脑·word
其实防守也摸鱼4 小时前
Day 3 · Agent Loop:从调用模型到控制循环 —— 课件精讲笔记
服务器·开发语言·javascript·数据库·人工智能·笔记·ecmascript
智购科技自动售货机厂家7 小时前
自动售货机外设接口与总线设计实战:串口、CAN 与 GPIO 的分工~YH
java·大数据·服务器·数据库·人工智能·单片机·嵌入式硬件
cndes7 小时前
出现 2013 lost connection to MySQL server during query
运维·服务器·数据库
xixiaoyunya8 小时前
服务器备份怎么做?覆盖文件、数据库、虚拟机并落地异地容灾
服务器·数据库·oracle
master3369 小时前
Linux 用户与权限体系:由浅入深完全指南
linux·运维·服务器
程序员与背包客_CoderZ11 小时前
Linux C++异步网络编程:c-ares高性能DNS解析编码实战
linux·服务器·c语言·开发语言·网络·c++·网络编程
Liekkas Kono12 小时前
VSCode 中如何使用 Astral 的 ty 类型检查器
ide·vscode·编辑器