VS Code デバッグ環境 on Windows
VS CodeでKotlin, C#, VB.NET, Javaを動かす環境構築メモ。
Extensions
.NET(C#, VB.NET)
1.Visual Studio 2019をインストール
C# 6.0(VS2015)から追加された「String Interpolation」を使用するため
※VS2019のコンパイラじゃなくてもいいなら2へ
String Interpolation(文字列補間)はこんなやつ
var x = 10; var y = 20; // C# 6.0以降 var str1 = $"{x}, {y}"; // C# 5.0以前 var str2 = string.Format("{0}, {1}", x, y);
2.環境変数のPathに追加
Code Runner実行時(コンパイル時)のコマンドcsc
やvbc
で
Visual Studioのコンパイラを使用するよう設定
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn
string.Formatでもいい場合はVS2019をインストールしなくても
下記をPathに追加すればOK
※下記のパスやコンパイラがあるか要確認
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
Kotlin
下記を参照
Java
1.JDKをインストール
2.環境変数のPathに追加
※Versionは確認して適宜変更
C:\Program Files\Java\jdk1.8.0_60\bin
3.settings.jsonを編集
{ "java.home": "C:\\Program Files\\Java\\jdk1.8.0_60", }
Code Runner
下記参照
executorMapByFileExtension
の.vb
や.kt
executorMap
のjava
やcsharp
のように設定すればOK
{ "code-runner.runInTerminal": true, "code-runner.saveFileBeforeRun": true, "code-runner.cwd": "C:\\work", "code-runner.executorMapByFileExtension": { ".vb": "cd $dir && vbc /nologo $fileName && $fileNameWithoutExt", ".vbs": "cscript //Nologo", ".scala": "scala", ".jl": "julia", ".cr": "crystal", ".ml": "ocaml", ".exs": "elixir", ".hx": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt", ".rkt": "racket", ".scm": "csi -script", ".ahk": "autohotkey", ".au3": "autoit3", ".kt": "cd $dir && kotlinc $fileName -include-runtime -d $fileNameWithoutExt.jar && java -jar $fileNameWithoutExt.jar", ".kts": "kotlinc -script", ".dart": "dart", ".pas": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt", ".pp": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt", ".d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt", ".hs": "runhaskell", ".nim": "nim compile --verbosity:0 --hints:off --run", ".csproj": "dotnet run --project", ".fsproj": "dotnet run --project", ".lisp": "sbcl --script", ".kit": "kitc --run" }, "code-runner.executorMap": { "javascript": "node", "java": "cd $dir && javac -encoding UTF-8 $fileName && java $fileNameWithoutExt", "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", "php": "php", "python": "python -u", "perl": "perl", "perl6": "perl6", "ruby": "ruby", "go": "go run", "lua": "lua", "groovy": "groovy", "powershell": "powershell -ExecutionPolicy ByPass -File", "bat": "cmd /c", "shellscript": "bash", "fsharp": "fsi", // csのdefault //"csharp": "scriptcs", //"csharp": "cd $dir && csc /nologo $fileName && $fileNameWithoutExt", // C#のバージョンを指定する際は「/langversion:7.0」や「/langversion:latest」のようにoption追加 // 指定できるバージョンの確認は「csc /langversion:?」 "csharp": "cd $dir && csc /nologo /langversion:latest $fileName && $fileNameWithoutExt", "vbscript": "cscript //Nologo", "typescript": "ts-node", "coffeescript": "coffee", "scala": "scala", "swift": "swift", "julia": "julia", "crystal": "crystal", "ocaml": "ocaml", "r": "Rscript", "applescript": "osascript", "clojure": "lein exec", "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt", "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt", "racket": "racket", "scheme": "csi -script", "ahk": "autohotkey", "autoit": "autoit3", "dart": "dart", "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt", "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt", "haskell": "runhaskell", "nim": "nim compile --verbosity:0 --hints:off --run", "lisp": "sbcl --script", "kit": "kitc --run" } }
これで4つの言語をVS CodeのCode Runnerで動かせます。
お試し環境の構築完了。