通过脚本一键安装配置VSCode便携版

完全独立、可迁移、可版本控制的 VSCode 开发环境

1.安装脚本

新建文件 install-vscode-portable.ps1,内容如下:

# 该脚本需通过powershell以管理员身份运行

# 安装目录与下载地址变量, 安装目录替换为你自己的目录!
$installDir = "D:\Dev\Tools\PortableApps\VSCode"
$vscodeUrl = "https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-archive"

# 创建目录结构
$dirs = @("$installDir")
foreach ($dir in $dirs) {
    if (-not (Test-Path $dir)) {
        New-Item -Path $dir -ItemType Directory -Force | Out-Null
    }
}

# 下载 VSCode 便携版
try {
    Invoke-WebRequest -Uri $vscodeUrl -OutFile "$env:TEMP\vscode.zip" -UseBasicParsing
} catch {
    Write-Host "错误:下载失败,请检查网络连接!" -ForegroundColor Red
    exit 1
}

# 解压到目标目录
Expand-Archive -Path "$env:TEMP\vscode.zip" -DestinationPath $installDir -Force

# 创建桌面快捷方式
$shortcutPath = [System.IO.Path]::Combine([Environment]::GetFolderPath("Desktop"), "VSCode.lnk")
$WScriptShell = New-Object -ComObject WScript.Shell
$shortcut = $WScriptShell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = "$installDir\Code.exe"
$shortcut.WorkingDirectory = $installDir
$shortcut.IconLocation = "$installDir\Code.exe, 0"
$shortcut.Save()

# 配置环境变量
[Environment]::SetEnvironmentVariable("VSCODE_PORTABLE", $installDir, "User")
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";%VSCODE_PORTABLE%", "User")

# 清理临时文件
Remove-Item -Path "$env:TEMP\vscode.zip" -Force

Write-Host "安装成功!快捷方式已创建到桌面。" -ForegroundColor Green

2.执行安装

  1. 右键点击开始菜单Windows Terminal (管理员)
  2. 执行以下命令:
    Set-ExecutionPolicy RemoteSigned -Force
    .\install-vscode-portable.ps1
    

3.命令行启动方法

# 普通模式
code .

# 安全模式(无插件)
code --disable-extensions

4.更新

  1. 从官网下载新版 ZIP
  2. 解压覆盖旧版文件(保留 user-dataextensions目录
  3. 重启 VSCode

5.高级配置

性能优化

user-data/User/settings.json 添加:

{
    "files.autoSave": "afterDelay",
    "search.exclude": {
        "**/node_modules": true,
        "**/__pycache__": true
    },
    "telemetry.enableTelemetry": false
}
  • 文件在编辑后 1 秒(默认延迟)自动保存
  • 搜索时排除node_modules__pycache__目录
  • 禁用 VSCode 匿名使用数据收集
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

羽翮will

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值