调试.NET Core源代码(Visual Studio 2019) [英] Debug .NET Core source (Visual Studio 2019)

查看:631
本文介绍了调试.NET Core源代码(Visual Studio 2019)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2019和.NET Core 3 Web应用程序.我想调试.NET Core源代码,因此当发生错误时,我可以深入研究代码并对其进行更详细的检查.由于我找不到确切的描述(即使在Microsoft文档站点上),因此在这里我将尝试总结到目前为止的知识.

我在Visual Studio中有以下选项:

I use Visual Studio 2019 and .NET Core 3 web application. I'd like to debug .NET Core source code, so when an error occurs I can dive into the code and examine it in more detail. As I couldn't find an exact description on how to do it (even on Microsoft documentation site), I'll try to summarize here what I know so far.

I have the following options in Visual Studio:

  1. 仅启用我的代码
  2. 启用.NET Framework源代码步进
  3. 启用源服务器支持
  4. 启用源链接支持
  1. Enable just my code
  2. Enable .NET framework source stepping
  3. Enable source server support
  4. Enable source link support

前两个选项是互斥的.我想我应该选择第二个选项,尽管我不理解".NET Framework"中的天气是否包括.NET Core?

现在,由于.NET Core是开源的,并且可以在GitHub上使用,所以我不了解3rd vs 4th选项.第三个应该允许我从Microsoft Symbol Servers中获取源代码(符号包括源吗?),而第四个应该允许我从GitHub中获取源代码?我需要一个吗?

首先,我在Main方法的CreateHostBuilder上放置一个断点,选择第三个选项并运行该应用程序.击中断点后,我继续进入代码(F11),直到出现一条消息,指出找不到GenericHostBuilderExtensions.cs".它使我可以浏览它,但是我不知道在哪里可以找到它.

让我们再试一次,这次选择第4个选项(然后取消选择第3个).现在,在断点被击中之后,VS让我通过Source Link下载前面提到的文件.接受,但结果是消息源链接错误:Azure DevOps:所有帐户的身份验证失败.使用文件->帐户设置..."添加新帐户或刷新凭据."好了,我已经使用Microsoft帐户登录了,我还应该怎么办?

我再重复一次,这次选择第3个和第4个选项.结果是一样的.

现在,我选择另一个Source Link选项:"Fall back to Git Credential manager ...",然后重新开始.结果相同.

当然,我广泛地搜索了Google,并花了很多时间试图找到解决方案,但我缺少了一些东西.非常感谢您提供有关上述选项的功能以及如何通过进入.NET Core源代码进行调试的帮助.

The first two options are mutually exclusive. I suppose I should select the second option, although I don't understand weather ".NET framework" in this options includes .NET Core?

Now as .NET Core is open source and available on GitHub, I don't understand 3rd vs 4th option. The 3rd should allow me to pull source from Microsoft Symbol Servers (do symbols include source?) while the 4th should allow me to pull source from GitHub? Do I need one or the other?

First, I put a breakpoint on CreateHostBuilder in Main method, select the 3rd option and run the application. After the breakpoint is hit I keep stepping into code (F11) until a message appears saying "GenericHostBuilderExtensions.cs is not found". It offers me to browse for it, but I have no idea where could I find it.

Let's try all over again, this time selecting the 4th option (and deselection the 3rd). Now, after the breakpoint is hit, VS offers me to download the before mentioned file by Source Link. A accept, but the result is the message "Source Link Error: Azure DevOps: Authentication failed for all accounts. Use 'File -> Account Settings...' to add a new account or refresh credentials." Well, I'm logged in with my Microsoft account, what else should I do?

I repeat it all again, this time selecting both 3rd and 4th options. Result is the same.

Now I select another Source Link option: "Fall back to Git Credential manager..." and start all over again. Same result.

Of course I extensively Googled and spent quite some time trying to find a solution, but I'm missing something. I'd appreciate help on what exactly the mentioned options do and how to debug by stepping into .NET Core source code.

推荐答案

也许此问题可以提供帮助 解决你的难题.

Maybe this issue can help solve your puzzle.

就像 vancem 所描述的那样,调试所需要做的一切.net核心来源是:

Just like what vancem describes in that issue, all you need to do for debugging .net core source is:

1.取消选中(工具->选项->调试->仅我的代码)"复选框.

1.Uncheck the (Tools -> Options -> Debugging -> Just My Code) checkbox.

2.确保已设置(工具->选项->调试->符号设置-> Microsoft Symbol Servers)复选框

2.Ensure that the (Tools -> Options -> Debugging -> Symbol Settings -> Microsoft Symbol Servers) checkbox is set

3.确保已选中(工具->选项->调试->启用源链接支持)

3.Ensure that the (Tools -> Options -> Debugging -> Enable Source Link support) checkbox is checked

找不到GenericHostBuilderExtensions.cs".

"GenericHostBuilderExtensions.cs is not found".

至于为什么你在这里失败.我认为这与我上面提供的问题类似.对于.net core 3.0预览版,其某些库当前在github中没有源链接,因此vs无法获取它们. (就像2017年的.net core 2.0一样,现在已修复)

As for why you fail here. I think it's similar to the issue I provides above. For .net core 3.0 preview, some of its libraries currently don't have source links in github so the vs can't fetch them. (Like .net core 2.0 in 2017, now it has been fixed)

实际上,如果您遵循上述选项,则会找到you can debug well .net core 2.x web-app,但可能会失败for not finding source links for .net core 3.0.

Actually, if you follow options above, you will find you can debug well .net core 2.x web-app, but may fail for not finding source links for .net core 3.0.

一种解决方法:

As a workaround:

1.您可以尝试从git手动获取源代码,然后转到解决方案->属性->调试源文件,然后将目录添加到包含源代码的目录"中,以检查是否对某些情况有所帮助. (感谢vancem对他的详细介绍)

1.You can try getting the source manually from git, and go solution -> Properties -> Debug Source Files, then add your directory to the 'Directories Containing Source Code' to check if it helps for some situation. (Which is describe in details by vancem, thanks to him)

2.GenericHostBuilderExtensions.cs的GenericHostBuilderExtensions.cs的源可以找到

2.And the source of GenericHostBuilderExtensions.cs of the GenericHostBuilderExtensions.cs can be found here.I reproduced same issue, and resolve it by download the xx.cs and find it during debugging.

3.但是我不得不说这种方式需要一些时间.因为不仅此文件没有源文件,否则我们将遇到类似的问题,并且必须通过从git获取相应的源来解决它,除非.net core3.0中的所有源都有其源链接.但这可能需要一段时间,对于由此带来的不便,我们深表歉意.我建议您可以将其发布在github上并在此处共享链接.对它感兴趣的成员将帮助投票.

3.But I have to say this way takes some time. Since not only this file has no source file, we will meet similar issues and have to resolve it by getting corresponding source from git unless all the source in .net core3.0 has its source links. But it may takes some time, sorry for this inconvenience. And I suggest you can post it on github and share link here. Members interested in it will help vote it.

希望以上所有都对您有帮助.

Hope all above helps.

这篇关于调试.NET Core源代码(Visual Studio 2019)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆