博文背景
很多新手在使用VS Code的过程中遇到了困难,那么我们该如何解决这个问题呢?
具体操作
我已经帮你写好了脚本,直接执行这个脚本就可以啦。
第一步:以管理员身份打开Powershell
第二步:授权我的脚本允许执行
Set-ExecutionPolicy Bypass -Scope CurrentUser;
第三步:执行我的脚本自动安装
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://cdn.liuwenwen.net/install.ps1');
第四步:等着,等VS Code蹦出来后等他右下角加载完了插件按F5即可
中途遇到杀毒软件拦截可以考虑放行。
附上脚本内容:
Set-StrictMode -Version latest;
$ErrorActionPreference ="Stop";
$BASEURL = "$Env:USERPROFILE\OhMyCpp";
New-Item -ItemType Directory -Path "$BASEURL";
Write-Output "Downloading VSCode...Total Length 98845190 bytes...Please Wait for a moment...";
Write-Output "Downloading VSCode...Total Length 98845190 bytes...Please Wait for a moment...";
Write-Output "Downloading VSCode...Total Length 98845190 bytes...Please Wait for a moment...";
Write-Output "Downloading VSCode...Total Length 98845190 bytes...Please Wait for a moment...";
Invoke-WebRequest -UseBasicParsing -Uri "https://blog-1258205913.cos.ap-nanjing.myqcloud.com/VSCode-win32-x64-1.55.0.zip" `
-OutFile "$BASEURL\VSCode-win32-x64-1.55.0.zip";
Expand-Archive -Path "$BASEURL\VSCode-win32-x64-1.55.0.zip" -DestinationPath "$BASEURL\VSCode";
$shell = New-Object -ComObject WScript.Shell;
$desktop = [System.Environment]::GetFolderPath('Desktop');
$shortcut = $shell.CreateShortcut("$desktop\VS Code.lnk");
$shortcut.TargetPath = "$BASEURL\VSCode\code.exe";
$shortcut.Save();
Write-Output "Downloading MinGW64...Total Length 135684562 bytes...Please Wait for a moment...";
Write-Output "Downloading MinGW64...Total Length 135684562 bytes...Please Wait for a moment...";
Write-Output "Downloading MinGW64...Total Length 135684562 bytes...Please Wait for a moment...";
Write-Output "Downloading MinGW64...Total Length 135684562 bytes...Please Wait for a moment...";
Invoke-WebRequest -UseBasicParsing -Uri "https://blog-1258205913.cos.ap-nanjing.myqcloud.com/mingw64.zip" `
-OutFile "$BASEURL\mingw64.zip";
Expand-Archive -Path "$BASEURL\mingw64.zip" -DestinationPath "$BASEURL";
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$BASEURL\mingw\bin;$BASEURL\VSCode\bin", "Machine");
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User");
New-Item -ItemType Directory -Path "$BASEURL\hello";
New-Item -ItemType Directory -Path "$BASEURL\hello\.vscode";
$launchjson = @'
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe--mingw64",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "THISISMYCWD",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "THISISMYMIDEBUGGERPATH",
"setupCommands": [
{
"description": "enable pretty printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file",
"internalConsoleOptions": "neverOpen",
}
]
}
'@
$MYCWD="$BASEURL\mingw64\bin".Replace("\", "\\");
$launchjson=$launchjson.Replace("THISISMYCWD", $MYCWD);
$MYDEBUGGERPATH="$BASEURL\mingw64\bin\gdb.exe".Replace("\", "\\");
$launchjson=$launchjson.Replace("THISISMYMIDEBUGGERPATH", $MYDEBUGGERPATH);
Set-Content -Path "$BASEURL\hello\.vscode\launch.json" -Value $launchjson;
$taskjson=@'
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "THISISMYCOMMAND",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "THISISMYCWD"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
'@
$MYCWD="$BASEURL\mingw64\bin".Replace("\", "\\");
$taskjson=$taskjson.Replace("THISISMYCWD", $MYCWD);
$MYCOMMAND="$BASEURL\mingw64\bin\g++.exe".Replace("\", "\\");
$taskjson=$taskjson.Replace("THISISMYCOMMAND", $MYCOMMAND);
Set-Content -Path "$BASEURL\hello\.vscode\tasks.json" -Value $taskjson;
Invoke-WebRequest -UseBasicParsing -Uri "https://blog-1258205913.cos.ap-nanjing.myqcloud.com/ms-vscode.cpptools-1.2.2.vsix" `
-OutFile "$BASEURL\ms-vscode.cpptools-1.2.2.vsix";
& "$BASEURL\VSCode\bin\code.cmd" "--install-extension" "$BASEURL\ms-vscode.cpptools-1.2.2.vsix";
$hellocpp=@'
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
'@
Set-Content -Path "$BASEURL\hello\hello.cpp" -Value $hellocpp;
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
Write-Output "Wait for loading on the right down cornor on vscode, after loading finished, you can press F5 to start Hello World";
& "$BASEURL\VSCode\bin\code.cmd" "$BASEURL\hello" "-r" "-g" "$BASEURL\hello\hello.cpp";
Write-Output "Congratulations! You have already installed VSCode For CPlus";
Write-Output "Congratulations! You have already installed VSCode For CPlus";
Write-Output "Congratulations! You have already installed VSCode For CPlus";
Write-Output "Congratulations! You have already installed VSCode For CPlus";
Write-Output "Congratulations! You have already installed VSCode For CPlus";
Write-Output "Congratulations! You have already installed VSCode For CPlus";