Senparc.Weixin.MP SDK micro-channel public platform tutorial (XXII): How to install Nuget (dll) project using the source code debugging

  Recently came across a developer Q: I use nuget installed Senparc.Weixin SDK, but some have been packaged process you want to debug, I do not want to direct additional source project, so there is no way to sync updates, and how should I do ?

  This is actually a very common and universally representative problems, solutions are also common, this article we'll learn how to source code dll project is already installed breakpoint debugging.

A configuration

  The first step : Open the Visual Studio 2019 (low version of the operating should also be similar)

  Step Two : Click the top menu [Tools]> [Options ...]

  The third step : In the [options] window, select the list on the left [debugging]

  Fourth step : in the right window:

    • Uncheck [Enable "Just My Code"]
    • Uncheck the [main process execution attributes and operation symbol (hosting only)]
    • [Uncheck Require source files to exactly match the original version]
    • There are other options according to their actual needs to be modified

  The following is my complete development environment configuration:

  

 

  Step Five : Click the left window of the currently selected current [symbol] below the [General], select the right side of the [server] NuGet.org symbol, then click on the upper right [+] number, add the address: HTTPS: // NuGet. smbsrc.net , and select:

 

    (The files containing the source code debugging positioning information) This step is used to define the symbol file, each subsequent debugging, will automatically load the relevant documents, in order to speed up, we can be the original cache, click on the bottom [] button to load all symbols, and then wait for the end of the cache.

  注意:预先加载需要耗费比较多的时间(我重新测试了一次大概用了 20 分钟),但是为了减少后面的反复等待时间,这是值得的(缓存并不会占用太多硬盘空间,请放心加载)。如果程序集有比较大的变化,或者发生问题,也可以使用下方的按钮清空并重新加载。

  设置完成后点击【确定】按钮。

 

二、试验

  下面让我们以 Senparc.Weixin SDK 来测试一下,顺便学习一下如何创建新项目和安装 nuget 包。

  第一步:打开 Visual Studio 2019

  

 

    第二步,点击【创建新项目】,选择【ASP.NET Core Web 应用程序】(也可以选择 .NET Framework 项目):

 

   第三步:点击【下一步】,配置项目名称、路径等参数,如:

 

   第四步:点击【创建】,在项目模板中选择【Web 应用程序】(也可以选择其他站点模板,主要为了演示调试过程,所以不重要):

 

   第五步:点击【创建】,完成原始项目的创建:

 

   第六步:对项目标题点右键,选择【管理 Nuget 程序包...】

 

   第七步:在打打的窗口中,选择【浏览】标签,在搜索框内输入:Senparc.Weixin.MP,回车:

 

   请注意:盛派官方发布的库都带有“盛派”Logo的库,并请仔细核对全名,有些库是第三方开发者发布的。

  第八步:选中【Senparc.Weixin.MP】,在右侧点击【安装】按钮,如弹出确认框,点击【我接受】。稍等片刻即可安装完成(如果无法安装,请更改 nuget 源,具体方法不在本文展开):

 

   第九步:打开 startup.cs,在 ConfigureServices() 方法中,写入代码((.NET Framework 项目可打开 global.asax.cs,在 Application_Start() 方法中):

var nonceStr = Senparc.Weixin.MP.Helpers.JSSDKHelper.GetNoncestr();

  说明:我们可以调试任意地方的代码,写在 startup.cs 中只是为了当前演示断点可以尽快获得。

 

  此时,我们已经可以在非调试状态下查看反编译的源码(这一步不是接下去使用断点调试源码必须的,只作为可以扩展):把光标移到 GetNoncestr 方法名上,点击鼠标右键,点击【转到定义】(或直接按 F12),此时会显示提示框,点击【是】,即可看到 dll 中的源代码:

 

   注意:此源代码是从 dll 反编译过来的源代码,已经在编译过程中进行了优化,因此未必每个字符都 100% 和源代码一致,甚至部分局部变量会被重新命名,但是最终执行结果是一致的,也不会影响到调试。

  关闭反编译源码的窗口(必须)*,然后回到 startup.cs,我们给 GetToken() 语句打上断点:

 

  最后一步(第十步):点击菜单【调试】>【开始调试】(或直接按 F5)运行程序(注意:请保证当前的编译模式为 Debug):

 

    静静等待断点命中,在此过程中,VS 会自动载入一系列跟踪源码需要的文件,可能需要一段时间,这取决于依赖包的数量和当前的网速:

 

     稍等之后,即可命中语句:

 

   键盘点击 F11,就像你调试当前解决方案中的代码一样(如果提示是否允许从 github 下载源代码,点击同意):

 

  可以看到,现在 VS 打开了 github 上源代码的窗口,此时如果继续点击 F11,可以进入到此方法中调用的 Guid.NewGuid() 的 .net core 的相关方法:

 

  现在连续点击 F10,我们让程序继续执行,并在 startup.cs 中返回结果:

 

  

PS:

  * 之所以在调试源码之前必须要关闭反编译的窗口,是因为反编译的代码(包括代码位置、名称定义)和源码相比通常都会有出入,如果在调试的时候,打开着反编译代码窗口,VS 会优先进入到反编译窗口进行调试,但是调试定位是根据符号文件定义的,也就是说定位的源代码的原始位置,此时可能就会出现偏差。

 

列教程索引

地址:http://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html

  1. Senparc.Weixin.MP SDK 微信公众平台开发教程(一):微信公众平台注册
  2. Senparc.Weixin.MP SDK 微信公众平台开发教程(二):成为开发者
  3. Senparc.Weixin.MP SDK 微信公众平台开发教程(三):微信公众平台开发验证
  4. Senparc.Weixin.MP SDK 微信公众平台开发教程(四):Hello World
  5. Senparc.Weixin.MP SDK 微信公众平台开发教程(五):使用Senparc.Weixin.MP SDK
  6. Senparc.Weixin.MP SDK 微信公众平台开发教程(六):了解MessageHandler
  7. Senparc.Weixin.MP SDK 微信公众平台开发教程(七):解决用户上下文(Session)问题
  8. Senparc.Weixin.MP SDK 微信公众平台开发教程(八):通用接口说明
  9. Senparc.Weixin.MP SDK 微信公众平台开发教程(九):自定义菜单接口说明
  10. Senparc.Weixin.MP SDK 微信公众平台开发教程(十):多客服接口说明
  11. Senparc.Weixin.MP SDK 微信公众平台开发教程(十一):高级接口说明
  12. Senparc.Weixin.MP SDK 微信公众平台开发教程(十二):OAuth2.0说明
  13. Senparc.Weixin.MP SDK 微信公众平台开发教程(十三):地图相关接口说明
  14. Senparc.Weixin.MP SDK 微信公众平台开发教程(十四):请求消息去重
  15. Senparc.Weixin.MP SDK 微信公众平台开发教程(十五):消息加密
  16. Senparc.Weixin.MP SDK 微信公众平台开发教程(十六):AccessToken自动管理机制
  17. Senparc.Weixin.MP SDK 微信公众平台开发教程(十七):个性化菜单接口说明
  18. Senparc.Weixin.MP SDK 微信公众平台开发教程(十八):Web代理功能
  19. Senparc.Weixin.MP SDK 微信公众平台开发教程(十九):MessageHandler 的未知类型消息处理
  20. Senparc.Weixin.MP SDK 微信公众平台开发教程(二十):使用菜单消息功能
  21. Senparc.Weixin.MP SDK 微信公众平台开发教程(二十一):在小程序中使用 WebSocket (.NET Core)
  22. Senparc.Weixin.MP SDK 微信公众平台开发教程(二十二):如何安装 Nuget(dll) 后使用项目源代码调试

Guess you like

Origin www.cnblogs.com/szw/p/debug-remote-source-code.html