通过Powershell /命令提示符在Windows上安装VS代码?

l7wslrjt  于 2023-11-21  发布在  Windows
关注(0)|答案(3)|浏览(174)

有没有一种方法可以通过Powershell /命令提示符命令在Windows上安装安装VS代码?就像在Linux中使用“sudo apt install.”
谢谢你

lxkprmvk

lxkprmvk1#

补充@Mohammed El Sayed使用Choco的伟大答案,现在Microsoft official package manager WinGet也可以让你做到这一点

winget install -e --id Microsoft.VisualStudioCode

字符串
注意-e匹配精确的字符串(而不是子字符串),--id将使用限制为应用程序的ID。More on args here
有关自定义安装的更多信息,请参阅GitHub discussion

nukf8bse

nukf8bse2#

你可以用巧克力

choco install vscode.install

字符串
参考:https://community.chocolatey.org/packages/vscode.install

xam8gpfp

xam8gpfp3#

您可以使用我在此存储库VSCode Installation中创建的自定义函数
这就是代码:

function Install-VSC-Windows {
    param (
        [Parameter()]
        [ValidateSet('local','global')]
        [string[]]$Scope = 'global',

        [parameter()]
        [ValidateSet($true,$false)]
        [string]$CreateShortCut = $true
    )

    # Windows Version x64
    # Define the download URL and the destination
    $Destination = "$env:TEMP\vscode_installer.exe"
    $VSCodeUrl = "https://code.visualstudio.com/sha/download?build=stable&os=win32-x64"

    # User Installation
    if ($Scope  -eq 'local') {
        $VSCodeUrl = $VSCodeUrl + '-user'
    }

    $UnattendedArgs = '/verysilent /mergetasks=!runcode'

    # Download VSCode installer
    Write-Host Downloading VSCode
    Invoke-WebRequest -Uri $VSCodeUrl -OutFile $Destination # Install VS Code silently
    Write-Host Download finished

    # Install VSCode
    Write-Host Installing VSCode
    Start-Process -FilePath $Destination -ArgumentList $UnattendedArgs -Wait -Passthru
    Write-Host Installation finished

    # Remove installer
    Write-Host Removing installation file
    Remove-Item $Destination
    Write-Host Installation file removed

    # Create Shortcut
    if ($CreateShortCut -eq $true)
    {
        Create-Shortcut -ShortcutName 'Visual Studio Code' -TargetPath 'C:\Program Files\Microsoft VS Code\Code.exe'
    }
}

function Create-Shortcut {
    param (
        [Parameter()]
        [ValidateNotNull()]
        [string[]]$ShortcutName,

        [parameter()]
        [ValidateNotNull()]
        [string]$TargetPath
    )

    Write-Host Creating Shortcut
    $WshShell = New-Object -comObject WScript.Shell
    $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\$ShortcutName.lnk")
    $Shortcut.TargetPath = $TargetPath
    $Shortcut.Save()
    Write-Host Shortcut created
}

# Call the function
Install-VSCode-Windows

字符串

相关问题