FAQ: How do I debug a custom rule?

本文介绍如何在FxCop及Visual Studio中调试自定义规则。内容涵盖使用FxCop UI进行调试的基础步骤,以及通过命令行进行调试的详细过程。特别关注于确保符号文件正确加载的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

While writing your custom rule, you will likely come across a need to debug it and work out why it's behaving in a particular manner.

Debugging within FxCop 

Debugging a custom rule within the FxCop UI is actually quite easy. To do so, simply:

  1. Open the FxCop project that contains your custom rule (making sure the PDB is alongside the assembly)
  2. Open the solution that contains your custom rule and set a breakpoint in the rule your want to debug
  3. Choose Debug -> Attach to Process
  4. Under Available Processes, choose FxCop.exe and click Attach
  5. In FxCop, choose Project -> Analyze

The debugger should break when it hits the breakpoint.

Debugging within Visual Studio or via command-line

However, if you want debug a rule that you've written for Visual Studio Code Analysis, or via the command-line, the procedure is not so obvious:

  1. Open a Visual Studio Command Prompt
  2. If debugging a custom rule written for Visual Studio, run the following:

    > cd %VSINSTALLDIR%\Team Tools\Static Analysis Tools\FxCop

    Otherwise, if debugging a custom rule written for FxCop, run the following:

    > cd %PROGRAMFILES%\Microsoft FxCop 1.35

  3. Run the following command, replacing [TargetAssembly] and [RuleAssembly] with the assembly you want to analyze and the assembly that contains your custom rule respectively.

    > devenv /debugexe FxCopCmd.exe /file:[TargetAssembly]/rule:[RuleAssembly] /console

    This will open Visual Studio in a state that is ready to debug your custom rule.

  4. Choose File -> Open -> File and browse to and open the source file that contains your custom rule

  5. Set a breakpoint in the rule

  6. Choose Debug -> Start Debugging

The debugger should break when it hits the breakpoint.

The Modules window is your friend

 

If the breakpoint is not being hit, check to make sure that you actually have symbols for your custom rule loaded:

  1. While debugging, choose Debug -> Windows -> Modules

    To do this if you are debugging via /debugexe switch, as soon as the command window opens to start running FxCop, click PAUSE on the keyboard.

  2. Look for your rule assembly and check under the Symbol Status column.
  3. If this column states anything other Symbols Loaded, then right-click on the assembly and choose Load Symbols and browse manually to the PDB.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值