如何在调试时让Visual Studio使用嵌入式源代码?

时间:2018-11-06 16:40:48

标签: c# visual-studio .net-core pdb-files

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

我的程序集看起来像这样:

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

我可以确认pdb是可移植类型,并且包含我的源代码:

Embedding C# sources in PDB with new csproj

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

enter image description here

我正在使用Visual Studio 2017(版本号15.8.8)

但是,当我F11进入程序集的代码时,它会要求提供源代码:

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

尽管在讨论enter image description here中有一个来自ctaggart的评论,其中说运行sourcelink print-url将打印“ embed”,但我的却不是,也许这是一个提示:

https://github.com/ctaggart/SourceLink/issues/192

有人能成功工作吗?如果可以,您能告诉我我在做什么错吗?

1 个答案:

答案 0 :(得分:1)

最简单的方法是转到:

Debug -> Windows -> Modules

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

Right click it -> Load Symbols

它将询问从何处加载符号。

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

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

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

我们还使用这些软件包打包了源代码,并且还导航到了这些/nuget/packages .cs文件,尽管任何corresponding .cs文件都应允许其加载。