507 words
3 minutes
How to set up C/C++/C#/Python with Visual Studio Code
2023-10-12
统计加载中...

C/C++#

Installation#

  1. Download Visual Studio Build Tools 2022 Installer and run it

  2. Open Visual Studio Build Tools 2022 and check the following options

  3. Go to Single Component section -> search for ‘MSVC (v14.38-17.8)’ and check it

  4. Click Install

  5. Edit System Environment Variables with the following variables

    [SYS] BuildTools: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
    [SYS] VCTools: %BuildTools%\VC\Tools
    [SYS] MSVC_VERSION: 14.42.34433
    [SYS] WIN_SDK_VERSION: 10.0.20348.0
    [SYS] WIN10KITS: C:\Program Files (x86)\Windows Kits\10
    [SYS] INCLUDE: %VCTools%\MSVC\%MSVC_VERSION%\include;%WIN10KITS%\Include\%WIN_SDK_VERSION%\ucrt;%WIN10KITS%\Include\%WIN_SDK_VERSION%\um;%WIN10KITS%\Include\%WIN_SDK_VERSION%\shared;
    [SYS] LIB: %WIN10KITS%\Lib\%WIN_SDK_VERSION%\um\x64;%WIN10KITS%\Lib\%WIN_SDK_VERSION%\ucrt\x64;%VCTools%\MSVC\%MSVC_VERSION%\lib\x64;
    [USER] Path:
    %VCTools%\MSVC\%MSVC_VERSION%\bin\Hostx64\x64
    %BuildTools%\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin

Configuration#

  1. Open Visual Studio Code

  2. Ctrl + Shift + X -> Search for “C/C++” -> Install Specific Version... -> 1.21.6 (Versions before 1.22.9)

  3. Ctrl + Shift + X -> Search for “CMake Tools”

  4. Ctrl + Shift + P -> Preferences: Open User Settings (JSON) -> Insert and set the following param:

    {
    "C_Cpp.intelliSenseEngineFallback": "enabled",
    "C_Cpp.default.compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe", // Change to your compiler's path
    "[cpp]": {
    "editor.semanticHighlighting.enabled": true,
    "editor.stickyScroll.defaultModel": "foldingProviderModel",
    "editor.suggest.insertMode": "replace",
    "editor.wordBasedSuggestions": "off"
    },
    "cmake.generator": "Visual Studio 17 2022", // Change to your cmake's generator
    "cmake.cmakePath": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe", // Change to your cmake's path
    "cmake.pinnedCommands": [
    "workbench.action.tasks.configureTaskRunner",
    "workbench.action.tasks.runTask"
    ],
    }

Run Example#

Beginner#

  1. Open Visual Studio Code

  2. (Optional) Ctrl + Shift + P -> C/C++: Edit Configurations (JSON) -> Add custom include dirs to “includePath”

  3. Create a cpp file and write something

  4. Press F5 and choose the configuration start with “C/C++“

Intermediate#

  1. Open Visual Studio Code

  2. (Optional) Ctrl + Shift + P -> C/C++: Edit Configurations (JSON) -> Add custom include dirs to “includePath”

  3. Create a cpp file and write something (and create a header file inside ‘include/’ directory if you want)

  4. (Optional) Ctrl + Shift + P -> Preferences: Open Workspace Settings (JSON) -> Insert and set the following param:

    {
    "cmake.configureOnOpen": false,
    "cmake.sourceDirectory": "${workspaceFolder}/", // Change to the dir where CMakeLists.txt will be stored
    }
  5. Create a CMakeLists.txt if not exists

    # Requiries
    cmake_minimum_required(VERSION 3.16)
    set(CMAKE_CXX_STANDARD 17)
    # Set project name
    project(name_of_the_project)
    # # Set header directories
    # include_directories(${PROJECT_SOURCE_DIR}/include)
    # Set output directory
    set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
    # Collect source files
    aux_source_directory(${PROJECT_SOURCE_DIR}/src SRC_LIST)
    # Create executable
    add_executable(
    name_of_the_exe
    ${SRC_LIST}
    )
  6. Ctrl + Shift + P -> CMake: Select a Kit -> Choose the kit starts with “Visual Studio”

  7. Ctrl + Shift + P -> CMake: Configure -> Select the designated CMakeLists.txt

C##

Installation#

Download Microsoft .NET SDK 8.0.411 Installer and run it

The following components should be installed:

  • .NET SDK 8.0.411
  • .NET Runtime 8.0.17
  • ASP.NET Core Runtime 8.0.17
  • .NET Windows Desktop Runtime 8.0.17

Configuration#

  1. Open Visual Studio Code

  2. Ctrl + Shift + X -> Search for “C#” -> Install

  3. Ctrl + Shift + P -> Preferences: Open User Settings (JSON) -> Insert and set the following params:

    {
    "omnisharp.useModernNet": false,
    "dotnetAcquisitionExtension.allowInvalidPaths": true,
    "dotnetAcquisitionExtension.existingDotnetPath": [], // Change to your dotnet's path
    }

Python#

Installation#

Configuration#

  1. Open Visual Studio Code

  2. Ctrl + Shift + X -> Search for “C#” -> Install

  3. Ctrl + Shift + P -> Preferences: Open User Settings (JSON) -> Insert and set the following params:

    {
    "python.defaultInterpreterPath": "C:/Users/Spr_Aachen/AppData/Local/Programs/Python/Python39/python.exe", // Change to your interpreter's path
    "[python]": {
    "diffEditor.ignoreTrimWhitespace": false,
    "editor.formatOnType": true,
    "editor.wordBasedSuggestions": "off"
    },
    }

Common#

Other recommanded settings for Visual Studio Code

  1. Open Visual Studio Code

  2. Ctrl + Shift + P -> Preferences: Open User Settings (JSON) -> Insert the following params:

    {
    "security.workspace.trust.untrustedFiles": "open",
    "editor.formatOnType": true,
    "editor.formatOnPaste": true,
    "editor.maxTokenizationLineLength": 100000,
    "diffEditor.experimental.showMoves": true,
    "diffEditor.maxComputationTime": 0,
    "git.suggestSmartCommit": true,
    "files.autoGuessEncoding": true,
    "workbench.startupEditor": "none",
    "workbench.editor.empty.hint": "text",
    }
How to set up C/C++/C#/Python with Visual Studio Code
https://blog.spr-aachen.com/posts/tutorial-visualstudiocode/setuplanguages/
Author
Spr-Aachen
Published at
2023-10-12
License
CC BY-NC-SA 4.0

Some information may be outdated

封面
Music
Artist
封面
Music
Artist
0:00 / 0:00