如何打包和部署带有符号和源代码的 NuGet 包,以便调试器可以使用该源代码? [英] How to package and deploy a NuGet package with symbols and source code so that debugger can use THAT source code?

查看:86
本文介绍了如何打包和部署带有符号和源代码的 NuGet 包,以便调试器可以使用该源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 .net 框架 Visual Studio 类库项目中创建了一个非常简单的 NuGet 包,其中类库源在 C# 中.

I have created a very simple NuGet package from a .net framework visual studio Class Library project, where the class library source is in C#.

我使用这个命令来创建 nuget 包:

I used this command to create the nuget package:

nuget pack MyProject.csproj -symbols -Properties "Configuration=Debug" -suffix debug

正如我所料,它创建了两个 nuget 包文件,即:

Which creates, as I expect, two nuget package file, namely:

  • MyProject.1.0.0-debug.symbols.nupkg
  • MyProject.1.0.0-debug.nupkg

除了带有符号"的包包括 lib 层次结构中的 pdb 文件和 src 文件夹中的源文件之外,这些包基本相同.

These packages are basically identical other than that the one with "symbols" includes the pdb files in the lib hierarchy and source files in the src folder.

鉴于重复,我将文件 MyProject.1.0.0-debug.symbols.nupkg 重命名为 MyProject.1.0.0-debug.nupkg,它会覆盖一个的文件,没什么大不了的.我现在有一个传统命名的包,其中包含 PDB 和源文件.

Given the duplication, I rename the file MyProject.1.0.0-debug.symbols.nupkg as MyProject.1.0.0-debug.nupkg, which overwrites one of the files, no big deal there. I now have a conventionally named package with PDB and source files in it.

我将其部署到内部文件共享源:

I deploy this to an internal file share feed with:

nuget add MyProject.1.0.0-debug.nupkg \\InternalShare\FeedFolder

在一个完全不同的项目和不同的解决方案中,我现在使用 NuGet 包管理器在 Visual Studio 中使用该 NuGet 包.一切都很好.并且代码也能正常工作,在我的例子中,我制作了一个简单的控制台应用程序,它使用了包中的几个类,并且我已经证明它可以正确使用它们并且没有发生任何事故.

In an entirely different project, and a different solution, I now consume that NuGet package in Visual Studio with the NuGet Package Manager. All works great. And the code works fine too, in my case I made a simple console app that uses a couple of classes in the package and I have demonstrated that it uses them correctly and without incident.

到目前为止一切顺利.

现在我在消费代码中设置了一个断点,并尝试单步调试包.它似乎工作正常,但实际上,它没有进入随包分发的源代码.它实际上从包的创建开始进入原始源代码,在我机器上完全不同且不相关的文件夹层次结构中.

Now I set a breakpoint in the consuming code, and attempt to step into the source to debug the package. It seems to work OK, but actually, it isn't going into the source that was distributed with the package. It actually steps into the ORIGINAL source from the creation of the package, in a completely different and unrelated folder hierarchy on my machine.

好的.所以现在我在没有原始源的单独计算机上重新创建我的简单控制台应用程序.在那台单独的计算机上,它位于内部网络上,因此可以访问文件共享,我使用 NuGet 包,再次,一切都可以编译并正常工作.

OK. So now I recreate my simple console app on a separate computer that does not have the ORIGINAL source. And on that separate computer, which is on the internal network and hence has access to the file share, I consume the NuGet package and again, everything compiles and works fine.

然而,当我尝试在 Visual Studio 调试器中单步执行包源代码时,它根本不起作用.调试器无法找到源代码,即使它就在包文件夹中.(调试器提供反汇编代码 - 没有太大帮助).

When I try to step into the package source code in the visual studio debugger, however, it simply doesn't work. The debugger can't find the source code even though it is right there in the package folder. (The debugger offers to disassemble the code -- not so helpful).

这似乎应该是一个常见的用例,并且希望在 nuget 包中包含符号和源代码,所以我一定是在做一些愚蠢的事情,以至于调试器找不到源代码.

This seems like it should be a common use case and desire for including symbols and source code in a nuget package, so I must be doing something silly such that the debugger can't find the source.

事物的各种版本:

  • Visual Studio:专业版 2017 15.9.11
  • 安装在 VS 中的 NuGet 包管理器:4.6.0
  • CLI NuGet 版本:4.8.1.5435
  • 我的示例代码的目标 .NET Framework:4.6.1

我的错误是什么?

非常感谢.

================== 添加信息 2019 年 4 月 17 日,太平洋时间下午 3:30 ========================

================== ADDED INFO 4/17/2019, 3:30pm Pacific =======================

这并不像我想象的那么糟糕.当我尝试进入代码并说找不到它时,我有机会浏览到代码,因此我可以浏览到包(假设我知道它在哪里!)并将调试器设置为宽松和一切正常.好消息是 Visual Studio 似乎记得我浏览过的地方,并且知道下次去那里看看.不确定那个机制.

This isn't quite as bad as I thought. When I try to go into the code and says it can't find it, I am given the opportunity to browse to the code, so I can browse to the package (assuming I know where it is!) and set the debugger loose and everything works fine. The nice thing is that Visual Studio seems to remember where I browsed to and knows to look there next time. Not sure of that mechanism.

AND.... 如果我转到我的原始计算机(上面有实际的包源),如果我更改了初始源,就像我为下一个包做准备一样,调试器(当然)会意识到来源已更改,同样提示我在别处寻找合适的来源.

AND.... If I go to my original computer (with the actual package source on it) if I change that initial source, like I am getting ready for the next package, the debugger (of course) realizes that the source has changed, and likewise prompts me to look for the proper source elsewhere.

不过,如果不必像那样跳槽就好了,所以我仍然希望能提供任何进一步的见解.

Still, it would be great not to have to jump through hoops like that, so I would still appreciate any further insights.

推荐答案

一些基础知识:

  • 调试器需要 PDB 来启用调试
  • 符号包应包含 PDB(它不仅仅是具有不同扩展名的包)
  • 应将此符号包发布到 Visual Studio 调试器可以从中请求符号的符号存储库

下一步:

  1. 有关创建和发布符号包的信息,请参阅此 文档 到 nuget.org (.snupkg)
  2. 然后,请参阅此 doc 用于配置 Visual Studio 以使用 NuGet.org 作为符号源(使用添加符号服务器时的此值 https://symbols.nuget.org/download/symbols)
  1. See this doc for creating and publishing symbols package to nuget.org (.snupkg)
  2. Then, see this doc for configuring visual studio to for using NuGet.org as a symbol source (use this value when adding a symbol server https://symbols.nuget.org/download/symbols)

这篇关于如何打包和部署带有符号和源代码的 NuGet 包,以便调试器可以使用该源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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