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

如何在Rider中设置控制台为交互模式?解决Spectre.Console异常

解决Rider中.NET 7控制台应用(Spectre.Console)非交互模式异常及终端格式问题

针对M1 Mac上Rider运行使用Spectre.Console的.NET 7控制台应用时出现的Failed to read input in non-interactive mode异常,以及终端无格式的问题,可按以下步骤排查修复:

调整运行配置核心设置

  • 打开运行/调试配置(点击右上角运行按钮旁下拉框,选择Edit Configurations...)
  • 找到对应的.NET控制台应用配置,确认:
    • 勾选Run in terminal:强制应用在交互式终端窗口中运行,而非内置Console标签页
    • 取消勾选Redirect input:避免输入被重定向导致进入非交互模式
    • 确认Working directory设置为项目输出目录,排除路径异常影响

重置Rider终端配置

  • 进入Rider > Settings(M1 Mac路径),导航到Tools > Terminal
  • 确保Shell path设置为系统默认终端(如/bin/zsh或/bin/bash)
  • 勾选Run terminal in interactive mode
  • 点击Reset to Defaults重置终端设置,重启Rider生效

代码层强制指定交互模式(可选)

若上述配置无效,可在代码中明确指定Spectre.Console使用交互模式:

var settings = new AnsiConsoleSettings
{
    Interactive = InteractionMode.Interactive,
    Out = new AnsiConsoleOutput(Console.Out)
};
var console = AnsiConsole.Create(settings);
// 使用该console对象替代AnsiConsole静态类执行输入操作
console.Ask<string>("请输入内容:");

验证系统终端兼容性

直接在系统终端(Terminal.app)运行应用,确认是否正常:

dotnet run --project 你的项目路径/YourProject.csproj

若系统终端运行正常,说明问题仅存在于Rider终端配置,而非代码或.NET环境

清理Rider缓存

  • 进入File > Invalidate Caches...
  • 选择Invalidate and Restart,清理缓存文件以修复潜在的配置异常

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 10:35:00