Visual Studio 调试 .net mvc 项目 Console.WriteLine 无法输出到控制台 解决方案

Intro

  • env

Visual Studio 2019 Community
.net framework 4.7.2

  • 解决
    使用了其他语句,将想要查看的信息打印在Output窗口。

Operation

4点:

  1. 输出语句必须使用 System.Diagnostics.Debug.WriteLine("22222");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcMovie.Controllers
{
    public class WyjController : Controller
    {
        public string Index()
        {
            Console.WriteLine("11111");
            System.Diagnostics.Debug.WriteLine("22222 " + DateTime.Now);	// 会输出到 Output
            return "访问成功 " + DateTime.Now;
        }
    }
}
  1. 必须打开Output窗口 Ctrl+Alt+O
    在这里插入图片描述
  2. 必须是调试而非运行,否则output中不会输出想要输出的信息。F5
功能本质快捷键菜单名(中文)菜单名(英文)
调试(Debug)F5开始调试Start Debugging
运行(Run)Ctrl+F5开始执行(不调试)Start Without Debugging

在这里插入图片描述

  1. 切换输出窗口显示的输出来源为调试/Debug

在这里插入图片描述

测试

在这里插入图片描述
访问规则: WyjController中的Index方法的访问path: /Wyj/Index/Wyj/
可以看到使用System.Diagnostics.Debug.WriteLine()输出的信息被打印。
测试成功。

Others

打印变量是最原始最基本的Debug方案。。

其实也可以通过Debug操作去调试/观察程序的运行细节。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值