kothru / TIL

Today I Learned
1 stars 0 forks source link

2022/12/21 VSCode C++ env #232

Open kothru opened 1 year ago

kothru commented 1 year ago

BuildToolsのインストール https://visualstudio.microsoft.com/ja/downloads/?q=build+tools

以下参考にmyproject.vcxproj作成 https://learn.microsoft.com/ja-jp/cpp/build/walkthrough-using-msbuild-to-create-a-visual-cpp-project?view=msvc-170

PATHを通しておく C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin https://learn.microsoft.com/ja-jp/visualstudio/msbuild/whats-new-msbuild-16-0?view=vs-2022

MSBuild.exe myproject.vcxproj -p:Configuration=Debug

kothru commented 1 year ago

デバッグ用のlaunch.json, ビルド用のtask.json登録しておくと便利

kothru commented 1 year ago

https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

kothru commented 1 year ago

gitignoreに以下追加

Debug/
.vscode/
kothru commented 1 year ago

.vscode\launch.json

{
  // IntelliSense を使用して利用可能な属性を学べます。
  // 既存の属性の説明をホバーして表示します。
  // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "(Windows) 起動",
      "type": "cppvsdbg",
      "request": "launch",
      "program": "${workspaceFolder}/Debug/myproject.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${fileDirname}",
      "environment": [],
      "console": "externalTerminal"
    },
  ]
}
kothru commented 1 year ago

.vscode\tasks.json

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "type": "shell",
      "command": "MSBuild.exe",
      "args": [
        // Ask msbuild to generate full paths for file names.
        "myproject.vcxproj",
        "-p:Configuration=Debug",
        // Do not generate summary otherwise it leads to duplicate errors in Problems panel
        // "/consoleloggerparameters:NoSummary"
      ],
      "group": "build",
      "presentation": {
        // Reveal the output only if unrecognized errors occur.
        "reveal": "silent"
      },
      // Use the standard MS compiler pattern to detect errors, warnings and infos
      "problemMatcher": "$msCompile"
    }
  ]
}