Watch + Search
值可以被编辑,实际上是真的改变了变量的值
Locals 和 Autos
- Locals: 执行的方法 所属的 local scope
- Autos: 断点周围 这个 scope
用哪个,看偏好
临时改变 执行流
拖拽 breakpoint,可跳过 或 重复 执行代码
临时 断点
不实际打断点,但是到那里会停下。方法有:
- 到那一行,右键,点击 运行到光标处
- 到那一行,右键,点击 设置下一条语句
- 到那一行, 点击 绿色的箭头按钮
edit and continue
debug 的过程当中,不停止调试,直接改code,接着调试
启用方式: Debug > Options > Debugging > General > Enable Edit and Continue
immediate Window
允许 输入commands 来测试我们的code的许多方面
- 执行表达式
- 执行语句
- 在当前的调试context下 管理变量
- 重新执行方法
输入
>
可以看到很多有用的命令
System.Dianostics名称空间下的类
用System.Dianostics名称空间下的类 和Debugger进行 互动
- Debug.WriteLine()
- Debug.Print()
- ...
- Debugger.IsAttached 有用,例如想只在debugger attach的时候执行这个code
- Debugger.Break() 写code的方式添加断点
- 对类使用attribute
DebuggerDisplay
: 来控制它在debugger看到的格式:[DebuggerDisplay("First Name = {FirstName} Approved = {Approved}")]
- 影响第一眼看到的格式
- 不影响展开后的内容
Trace point
打log到输出窗口
- 可以用于打印变量的历史
- 如果只选择 "操作"的话,就不会停下来
Code Map
VS 企业版才有。用于visualize call stack
Symbols
symbol 文件, 为调试器 提供了source code和 compiled code 之间的mappings
- program debug database (pdb) files
Source Link
- 往往Nuget packages中没有symbols文件
Source Link 允许我们调试 Nuget packages中定义的source code
为什么 Source link 能做到?
- 往Nuget packages中加metadata 和symbol files
- visual studio利用meta data 从版本管理系统上 得到 source code . e.g. 从github上
- 有了source code和symbol, 就可以debug了
如何启用Source Link?
- 需要启用Source Link
启用方式: Debug > Options > Debugging > General > Enable Source Link support
要使用Source Link, 需要两个方面都做到:
- Source Link 在产生这个Nuget package的时候 执行
- 确保 Nuget package 集成了 Source Link
- 集成了的话,意味着 包含metadata 和 symbol
- 确保 Nuget package 集成了 Source Link
- Source Link 在消费这个Nuget package的时候 应用
- 添加Nuget symbol server 到 visual studio通常找PDB的地方
- 选择第一个
- 添加Nuget symbol server 到 visual studio通常找PDB的地方
Remote Debugging
- 调试Javascript
- client side code 跑在浏览器中
- 调试 在另一台机器上跑的 程序
- 例如:Azure App Services
- 例如:网络上的其他物理机
- 调试产品
- 不能单步调试
- 有现场
调试Javascript
启用方式: Debug > Options > Debugging > General > Enable Javascript debugging for ASP.NET (Chrome, Edge and IE)
- 方式一:
- 在Javascript的code上打断点
- start with debugger
- 方式二:
- 在Javascript的code上打断点
- 将浏览器的debug mode开启
- 在VS里,start without debugging
- attach到浏览器上
调试远程机器上的程序
- 安装remote debugging tools.
- 链接:(远程调试 - Visual Studio (Windows) | Microsoft Docs)
- 需要重启机器
- 安装在没有VS的那台远程机器上
- 开始菜单里 启动remote debugger
- 显式 机器名称 和 端口号
- 在有VS的机器上,attach to process
- Connection target 填写 机器名:端口号
- 填写credential
远程调试Azure App Service
- View > Cloud Explorer
- 找到对应的App Service
- 右键 Attach Debugger 或者 Attach Snapshot Debugger
dotnet XXX.dll 这样run起来的程序,就找dotnet.exe
Azure Services
- Cloud Storage
- Virtual Machines
- Function Apps
- Databases
- Active Directory
- App Services
基本的 Azure Deployment 流程
- 创建一个Azure Subscription
- 选择一个 hosting plan
- 创建一个 resource group
- 创建一个 application service
- 从vs里,将我们的project deploy到app service