C# 入门一:vscode运行与调试

一:创建C# 官方文档

1,安装vscode

2,安装插件 C#

3,初始化项目: dotnet new console --framework net6.0

4,运行:dotnet run

二:调试

1,安装 net6.0 sdk :下载SDK

2,按键 F5 (mac: 长按fn键,就会出现有F1-F12,或者自行百度)

3,选择vscode 左边页签 调试与运行 出现如下界面:

C# 入门一:vscode运行与调试_第1张图片C# 入门一:vscode运行与调试_第2张图片

 

4,自动生成文件:.vscode目录、launch.json、tasks.json 

 C# 入门一:vscode运行与调试_第3张图片

 

 5,launch.json内容

{
    "version": "0.2.0",
    "configurations": [
        {
            // Use IntelliSense to find out which attributes exist for C# debugging
            // Use hover for the description of the existing attributes
            // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/Study_Class/bin/Debug/net5.0/Study_Class.dll",
            "args": [],
            "cwd": "${workspaceFolder}/Study_Class",
            // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach"
        }
    ]
}

6,tasks.json 内容

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/Study_Class/Study_Class.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/Study_Class/Study_Class.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "${workspaceFolder}/Study_Class/Study_Class.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

注意点:因为开始我没有按照net6.0 SDK,后续安装的,所以调试文件的生成可能会跟我这边不一致,安装步骤提示往下走就行。只要生成了 launch.json、tasks.json 文件即可。

参考资料:创建C#项目

你可能感兴趣的:(C#,vscode,c#,ide)