You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux下VS Code调试C#控制台应用的终端配置问题

Linux下VS Code调试C#终端应用解决方案

你的问题根源在于当前使用的dotnet类型调试配置不支持console属性,换成coreclr类型配置即可解决属性不允许的问题,以下是具体操作步骤:

  • 替换调试配置类型:修改launch.json中的配置字段,将"type": "dotnet"改为"type": "coreclr",移除无效的launchConfigurationId,添加console配置项。示例配置如下:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C#: Events Example",
            "type": "coreclr",
            "request": "launch",
            "project": "${workspaceFolder}/Event/Event.csproj",
            "console": "integratedTerminal"
        }
    ]
}
  • 可选配置调整:如果需要更精细控制,也可以指定程序路径和工作目录:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C#: Events Example",
            "type": "coreclr",
            "request": "launch",
            "program": "${workspaceFolder}/Event/bin/Debug/net6.0/Event.dll",
            "cwd": "${workspaceFolder}/Event",
            "console": "integratedTerminal"
        }
    ]
}

注意:将net6.0替换为你项目实际使用的.NET版本,可从.csproj文件的TargetFramework字段获取。

  • 终端类型切换:若集成终端仍有问题,可将"console": "integratedTerminal"改为"console": "externalTerminal",调试时会调用系统默认终端启动应用,同样支持控制台交互。

保存配置后启动调试,C#应用即可正常读取控制台输入,不会再触发ReadKey相关的InvalidOperationException。

内容的提问来源于stack exchange,提问作者livan3li

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 22:27:24