如何调试从 TeamCity 部署的我的 nuget 包?

How to debug into my nuget package deployed from TeamCity?(如何调试从 TeamCity 部署的我的 nuget 包?)

本文介绍了如何调试从 TeamCity 部署的我的 nuget 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的团队使用的库放入从 TeamCity 部署到网络文件夹的 nuget 包中.我无法调试到这段代码!SymbolSource 是我读过的一种解决方案,但我更愿意找到某种方法来直接从 TeamCity 访问 .pdb/source 文件.有谁知道怎么做?

编辑.当我在 Nuget Pack 构建步骤中检查 'Include Symbols and Source' 时,TeamCity 会在 .nupkg 文件之外创建一个 .Symbol.nupkg网络文件夹..Symbol.nupkg 包含 src 和 .pdb 文件.

编辑.我取消选中 TeamCity 上的 'Include Symbols and Source' 并将以下内容添加到我的 nuspec 文件中:

 <files><文件 src="..MyLibraryin
eleaseMyLibrary.dll"目标=lib
et40";/><文件 src="..MyLibraryin
eleaseMyLibrary.pdb"目标=lib
et40";/><文件 src="..MyLibrary*.cs"目标=src";/><file src="..MyLibrary***.cs"目标=src";/></文件>

这在 nuget 包中添加了我的库的 dll、pdb 和源文件,并且没有生成我认为只有符号服务器才需要的 .Symbols 文件.

解决方案

传统方法

  1. 将 pdb 与 dll 放在 NuGet 包中.
  2. 将源代码添加到引用包的解决方案的调试源文件中.

这意味着您将能够单步执行代码并查看异常,但您可能必须先在磁盘上找到一个文件并打开它,然后才能设置断点.显然,您需要注意源的版本是否正确.

关于步骤的更多细节

如果您当前在没有 Nuspec 的情况下打包,则需要创建一个 Nuspec,然后将 pdb 添加到 lib 文件夹中的文件列表中NuGet spec"可能是生成初始规范的有用命令在

<小时>

公共或私人回购的现代方式

为确保源代码的确切版本可用,请在构建时将其嵌入.

从 Visual Studio 2017 15.5+ 开始,您可以添加 EmbedAllSources 属性:

<Project Sdk="Microsoft.NET.Sdk"><属性组><EmbedAllSources>true</EmbedAllSources>

公共回购的现代方式

为了保持你的 nuget 和库的大小,你可以使用 sourcelink 包.

它会生成一个 pdb,将调试器定向到来自您的 VCS 提供商(例如 GitHub、BitBucket)的文件的正确版本.

I have put a library that my team uses into a nuget package that is deployed from TeamCity into a network folder. I cannot debug into this code though! SymbolSource is one solution I have read about but I would much rather find some way to have access to the .pdb/source files directly from TeamCity. Does anyone know how to do this?

Edit. When I check 'Include Symbols and Source' in the Nuget Pack build step, TeamCity creates a .Symbol.nupkg in addition to the .nupkg file in the network folder. The .Symbol.nupkg contains the src and the .pdb file.

Edit. I unchecked 'Include Symbols and Source' on TeamCity and added the following to my nuspec file:

  <files>
    <file src="..MyLibraryin
eleaseMyLibrary.dll" target="lib
et40" />
    <file src="..MyLibraryin
eleaseMyLibrary.pdb" target="lib
et40" />
    <file src="..MyLibrary*.cs" target="src" />
    <file src="..MyLibrary***.cs" target="src" />
  </files>

This added the dll, the pdb, and the source files for my library in the nuget package and didn't generate a .Symbols file which I think is only needed for symbol servers.

解决方案

Traditional method

  1. Put the pdb in the NuGet package alongside the dll.
  2. Add the source code to the Debug Source Files for the solution that references the package.

This means you'll be able to step through code and view exceptions, but you might have to find a file on disk and open it before you can set a breakpoint. Obviously you need to be careful that the source is at the right revision.

More detail on step

If you're currently packaging without a Nuspec, you'll need to create a Nuspec, then add the pdb to the list of files in the lib folder "NuGet spec" may be a useful command for generating the initial spec as defined in NuGet docs. Then ensure the Team City Nuget Pack step is referencing your new nuspec.

More detail on step 2

When you have a solution open, right click on Solution, select Properties...Common Properties...Debug Source Files, and add the root source directory for the relevant binary reference. Or see MSDN. Note, you can't open the solution properties while debugging.

Still not hitting breakpoints?

Try disabling this from Tools->Options:


Modern way for public or private repos

To ensure the exact version of the source is available, embed it at build time.

From Visual Studio 2017 15.5+ you can add the EmbedAllSources property:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <EmbedAllSources>true</EmbedAllSources>

Modern way for public repos

To keep your nuget and library size small, you can use the sourcelink package.

It generates a pdb that directs the debugger to the correct version of the file from your VCS provider (e.g. GitHub, BitBucket).

这篇关于如何调试从 TeamCity 部署的我的 nuget 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何调试从 TeamCity 部署的我的 nuget 包?

基础教程推荐