Visual Studio Code

Um dir den Umstieg von PowerShell ISE zu Visual Studio Code einfach zu machen, haben wir diese Seite erstellt. Hier findest du die wichtigsten Funktionen, Konfigurationen und Befehle im Umgang mit VSCode.

Installation (als Administrator)

choco install vscode -y

Update (als Administrator)

choco upgrade vscode -y

Einstellungen

Folgende Einstellungen kannst du direkt übernehmen oder anpassen in der „settings.json“ Datei, diese findest du hier: „%appdata%\Code\User\settings.json“

{
// Alle Infos dazu findest du auf folgender Webseite:
// https://germanpowershell.com/visual-studio-code/
// © 2019 by www.germanpowershell.com
// Version 1.1
"workbench.colorTheme":"PowerShell ISE",
"workbench.iconTheme":"material-icon-theme",
"files.defaultLanguage":"powershell",
"files.trimTrailingWhitespace":true,
"files.autoSave":"afterDelay",
"files.associations":{
"*.ps1":"powershell"
},
"editor.tabCompletion":"on",
"editor.mouseWheelZoom":true,
"editor.minimap.enabled":false,
"editor.renderWhitespace":"all",
"editor.renderControlCharacters":true,
"editor.wordWrap":"on",
"editor.formatOnType":true,
"editor.formatOnPaste":true,
"editor.fontFamily":"'Segoe UI', 'Courier New', monospace",
"editor.fontSize":18,
"editor.fontWeight":"400",
"powershell.scriptAnalysis.enable":true,
"powershell.integratedConsole.focusConsoleOnExecute":false,
"powershell.enableProfileLoading":true,
"powershell.powerShellExePath":"C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"powershell.integratedConsole.showOnStartup":false,
"terminal.integrated.fontFamily":"Consolas",
"terminal.integrated.fontSize":18,
"terminal.integrated.lineHeight":1,
"terminal.integrated.shell.windows":"C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"[powershell]": { "files.encoding": "utf8bom", "files.autoGuessEncoding": false}
}

Wichtigste Erweiterungen

PowerShell

German Language Pack for Visual Studio Code

Material Icon Theme

Notepad++ keymap

Schnipsel (Snippets)

Diesen Code an folgenden Ort kopieren „%appdata%\Code\User\Snippets“ die Datei benennen mit „powershell.json“

Falls dir ein Schnipsel noch fehlt oder du was geändert haben möchtest, teile uns dies über unser Input-Formular mit.

{
// Alle Infos dazu findest du auf folgender Webseite:
// https://germanpowershell.com/visual-studio-code/
// © 2019 by www.germanpowershell.com
// Version 1.0

"Do...while Schleife": {
"prefix": "do",
"body": [
"do {",
"\t$0",
"} while (${$variable});"
],
"description": "Do...while Schleife"
},

"Do...until Schleife": {
"prefix": "do",
"body": [
"do {",
"\t$0",
"} until (${$variable});"
],
"description": "Do...until Schleife"
},

"Else Bedingung": {
"prefix": "else",
"body": [
"else {",
"\t$0",
"}"
],
"description": "Else Bedingung"
},

"ElseIf Bedingung": {
"prefix": "elseif",
"body": [
"elseif (${$variable}) {",
"\t$0",
"}"
],
"description": "Elseif Bedingung"
},

"Foreach Schleife": {
"prefix": "foreach",
"body": [
"foreach (${$item} in ${$collection}) {",
"\t$0",
"}"
],
"description": "Foreach Schleife"
},

"For Schleife": {
"prefix": "for",
"body": [
"for (${$i} = 0; ${$i} -lt ${$length}; ${$i}++) {",
"\t$0",
"}"
],
"description": "For Schleife"
},

"If Bedingung": {
"prefix": "if",
"body": [
"if (${$variable}) {",
"\t$0",
"}"
],
"description": "If Bedingung"
},

"For Schleife rückwärts": {
"prefix": "forr",
"body": [
"for (${$i} = ${$length} - 1; ${$i} -ge 0; ${$i}--) {",
"\t$0",
"}"
],
"description": "For Schleife rückwärts"
},

"Switch Bedingung": {
"prefix": "switch",
"body": [
"switch (${$variable}) {",
"\t${condition} { ${action}; break }",
"\tDefault {}",
"}"
],
"description": "Switch Bedingung"
},

"Try catch": {
"prefix": "try",
"body": [
"try {",
"\t${_}",
"}",
"catch [${System.Exception}] {",
"\t# Exception is stored in the automatic variable $_",
"\t$0",
"}"
],
"description": "Try catch Fehlerbehandlung"
},

"Try catch finally": {
"prefix": "trycf",
"body": [
"try {",
"\t${_}",
"}",
"catch [${System.Exception}] {",
"\t# Exception is stored in the automatic variable $_",
"\t$0",
"}",
"finally {",
"\t$1",
"}" ],
"description": "Try catch finally Fehlerbehandlung"
},

"Try finallly Fehlerbehandlung": {
"prefix": "tryf",
"body": [
"try {",
"\t${_}",
"}",
"finally {",
"\t$0",
"}"
],
"description": "Try finally Fehlerbehandlung"
},

"While Schleife": {
"prefix": "while",
"body": [
"while (${$variable}) {",
"\t$0",
"}"
],
"description": "While Schleife"
},

"Class": {
"prefix": "class",
"body": [
"class ${Name} {",
"\t$0",
"}"
],
"description": "Class Konstruieren"
},

"Enum": {
"prefix": "enum",
"body": [
"enum ${Name} {",
"\t$0",
"}"
],
"description": "Enum Konstruieren"
},

"Method": {
"prefix": "meth",
"body": [
"[$1] $2() {",
"\t$0",
"}"
],
"description": "Method Konstruieren"
},

"Property": {
"prefix": "prop",
"body": [
"[${string}] ${$Property}$0"
],
"description": "Class property Konstruieren"
},

"Property hidden": {
"prefix": "proph",
"body": [
"hidden [${string}] ${$Property}$0"
],
"description": "Hidden class property Konstruieren"
},

"Function": {
"prefix": "func",
"body": [
"function $1() {",
"\t$0",
"}"
],
"description": "Function Konstruieren"
},

"Function advanced": {
"prefix": "funcadv",
"body": [
"<#",
".SYNOPSIS",
"\tKurzbeschreibung der Funktion",
".DESCRIPTION",
"\tLange Beschreibung der Funktion",
".EXAMPLE",
"\tBeispiel Code um diese Funktion zu verwenden",
".EXAMPLE",
"\tEin anderes Beispiel diese Funktion zu verwenden",
"#>",
"function ${verb}-${noun} {",
"\t[CmdletBinding()]",
"\t[OutputType([${int}])]",
"\tparam(",
"\t\t[Parameter(Mandatory=$true)]",
"\t\t[${string}]",
"\t\t${Param1}",
"\t)",
"\t",
"\tbegin {",
"\t}",
"\t",
"\tprocess {",
"\t\t$0",
"\t}",
"\t",
"\tend {",
"\t}",
"}"
],
"description": "Advanced function Konstruieren"
},

"Help": {
"prefix": "help",
"body": [
"<#",
".SYNOPSIS",
"\tKurzbeschreibung",
".DESCRIPTION",
"\tLange Beschreibung",
".PARAMETER Path",
"\tPfad zu einer oder mehreren Orten.",
".PARAMETER LiteralPath",
"\tWie der 'Path' jedoch absolut, also ohne Platzhalter oder Variabeln.",
".PARAMETER InputObject",
"\tSpezifiziert das InputObject für diesen Befehl.",
".EXAMPLE",
"\tC:\\PS>",
"\tBeispiel dieses Cmdlet zu verwenden",
".EXAMPLE",
"\tC:\\PS>",
"\tAnderes Beispiel",
".INPUTS",
"\tInputs/Eingaben für diesen Befehl (falls vorhanden)",
".OUTPUTS",
"\tOutput/Ausgaben für diesen Befehl (falls vorhanden)",
".NOTES",
"\tAllgemeine Notizen",
".COMPONENT",
"\tKomponenten, welche dieses Cmdlet benötigt",
".ROLE",
"\tDie Rolle auf welche das Cmdlet aufbaut",
".FUNCTIONALITY",
"\tDie Funktionalität dieses Cmdlets",
"#>"
],
"description": "Hilfe Kommentar-Block Konstruieren"
}
}

Videos/Beiträge zu diesem Thema

VisualStudio Code konfigurieren

PowerSHELL auf Ubuntu

 

Schreibe einen Kommentar