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

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

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

lxkprmvk

lxkprmvk1#

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

  1. winget install -e --id Microsoft.VisualStudioCode

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

nukf8bse

nukf8bse2#

你可以用巧克力

  1. choco install vscode.install

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

xam8gpfp

xam8gpfp3#

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

  1. function Install-VSC-Windows {
  2. param (
  3. [Parameter()]
  4. [ValidateSet('local','global')]
  5. [string[]]$Scope = 'global',
  6. [parameter()]
  7. [ValidateSet($true,$false)]
  8. [string]$CreateShortCut = $true
  9. )
  10. # Windows Version x64
  11. # Define the download URL and the destination
  12. $Destination = "$env:TEMP\vscode_installer.exe"
  13. $VSCodeUrl = "https://code.visualstudio.com/sha/download?build=stable&os=win32-x64"
  14. # User Installation
  15. if ($Scope -eq 'local') {
  16. $VSCodeUrl = $VSCodeUrl + '-user'
  17. }
  18. $UnattendedArgs = '/verysilent /mergetasks=!runcode'
  19. # Download VSCode installer
  20. Write-Host Downloading VSCode
  21. Invoke-WebRequest -Uri $VSCodeUrl -OutFile $Destination # Install VS Code silently
  22. Write-Host Download finished
  23. # Install VSCode
  24. Write-Host Installing VSCode
  25. Start-Process -FilePath $Destination -ArgumentList $UnattendedArgs -Wait -Passthru
  26. Write-Host Installation finished
  27. # Remove installer
  28. Write-Host Removing installation file
  29. Remove-Item $Destination
  30. Write-Host Installation file removed
  31. # Create Shortcut
  32. if ($CreateShortCut -eq $true)
  33. {
  34. Create-Shortcut -ShortcutName 'Visual Studio Code' -TargetPath 'C:\Program Files\Microsoft VS Code\Code.exe'
  35. }
  36. }
  37. function Create-Shortcut {
  38. param (
  39. [Parameter()]
  40. [ValidateNotNull()]
  41. [string[]]$ShortcutName,
  42. [parameter()]
  43. [ValidateNotNull()]
  44. [string]$TargetPath
  45. )
  46. Write-Host Creating Shortcut
  47. $WshShell = New-Object -comObject WScript.Shell
  48. $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\$ShortcutName.lnk")
  49. $Shortcut.TargetPath = $TargetPath
  50. $Shortcut.Save()
  51. Write-Host Shortcut created
  52. }
  53. # Call the function
  54. Install-VSCode-Windows

字符串

展开查看全部

相关问题