如何在调试时让 Visual Studio 使用嵌入式源代码? [英] How can I get Visual Studio to use Embedded Source code whilst debugging?

查看:34
本文介绍了如何在调试时让 Visual Studio 使用嵌入式源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 csproj 文件中的 <EmbedAllSources> 元素将 C# 源代码嵌入到一个可移植的 PDB 文件中,并且我已经使用 < 将 pdb 嵌入到程序集中.DebugType>embedded<DebugType>

根据 Visual Studio 15.5 的发行说明,调试器应该能够在调试期间使用这些文件:

在谷歌搜索时,讨论中有来自 ctaggart 的评论

有没有人让它成功运行?如果是这样,你能告诉我做错了什么吗?

解决方案

最简单的方法是去:

<代码>调试->窗口 ->模块

在这个列表中,您应该能够找到您的程序集(dll/exe).

右键单击它 ->加载符号

它会询问从哪里加载符号.

导航到匹配的 .pdb 文件所在的目录.

它应该自动加载.步入或在此引用的程序集中出现未捕获的错误应触发该代码的中断,或要求您导航到与引发错误的文件对应的代码文件.

在我们的过程中,我们通常必须导航到 nuget 缓存以找到我们已安装的 nuget 包的 pdb.(%UserProfile%/nuget/packages/YourPackage/VersionNumber/../..)

我们还用这些包打包源代码并导航到那些 /nuget/packages .cs 文件,不过,任何 相应的 .cs 文件都应该允许它装载.

I have embedded the C# source code into a portable PDB file using the <EmbedAllSources> element in the csproj file, and I have embedded the pdb into the assembly using the <DebugType>embedded<DebugType> as described in Embedding C# sources in PDB with new csproj

My assembly looks like this:

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>    
    <EmbedAllSources>true</EmbedAllSources>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>embedded</DebugType>   
</PropertyGroup>

I can confirm that the pdb is type portable, and contains my source code:

According to the release notes for Visual Studio 15.5 the debugger should be able to use these files during debugging:

https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.5#EmbeddedSource

I'm using Visual Studio 2017 (version number 15.8.8)

However, when I F11 into the code from my assembly it asks for the sourcecode:

Whilst googling around there's a comment from ctaggart in the discussion https://github.com/ctaggart/SourceLink/issues/192 which says running sourcelink print-urls will print "embed" but mine doesn't, perhaps this is a hint:

Has anyone got this to work successfully? If so can you tell what I'm doing wrong?

解决方案

Easiest way is to go to:

Debug -> Windows -> Modules

Inside this list, you should be able to find your assembly (dll/exe).

Right click it -> Load Symbols

It will ask for where to load the symbols from.

Navigate to the directory where your matching .pdb file is.

It should auto load. Stepping into, or having uncaught errors in this referenced assembly should trigger a break in that code, or ask you to navigate to the code file that corresponds to the file that threw the error.

In our process, we generally have to navigate to the nuget cache to find the pdbs for our installed nuget packages. (%UserProfile%/nuget/packages/YourPackage/VersionNumber/../..)

We also package up the source with those packages and navigate to those /nuget/packages .cs files as well, though, any corresponding .cs file should allow it to load.

这篇关于如何在调试时让 Visual Studio 使用嵌入式源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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