简体   繁体   English

调试Nuget包时找不到符号源代码

[英]Cannot find Symbol Source code when debugging Nuget package

I have a build server that builds an internal Nuget package. 我有一个构建服务器,构建一个内部Nuget包。 When I use that package and try to step into a method it doesnt work. 当我使用该包并尝试进入一个方法时,它不起作用。

All symbols are published to my symbols server and I have enabled this in my VS settings. 所有符号都发布到我的符号服务器,我在VS设置中启用了这个符号。

If I check the Modules window I see that the Nuget DLL is there and the correct symbols are loaded for it and from the symbols server. 如果我检查模块窗口,我看到Nuget DLL在那里,并为它和符号服务器加载了正确的符号。

However when I try to step into the code it jumps right over the method. 但是,当我尝试进入代码时,它会跳过该方法。 If I use the call stack to specifically view that line of code it says "ClientBase.cs not found". 如果我使用调用堆栈专门查看该行代码,则会显示“ClientBase.cs not found”。 If I expand the "Source Search Information" I see this: 如果我扩展“源搜索信息”,我会看到:

Locating source for 'C:\\Build Agent\\vsts-agent-win7-x64-2.117.1_work\\1\\s\\ClientsShared\\Class\\ClientBase.cs'. 找到'C:\\ Build Agent \\ vsts-agent-win7-x64-2.117.1_work \\ 1 \\ s \\ ClientsShared \\ Class \\ ClientBase.cs'的源代码。 (No checksum.) (没有校验和。)

The file 'C:\\Build Agent\\vsts-agent-win7-x64-2.117.1_work\\1\\s\\ClientsShared\\Class\\ClientBase.cs' does not exist. 文件'C:\\ Build Agent \\ vsts-agent-win7-x64-2.117.1_work \\ 1 \\ s \\ ClientsShared \\ Class \\ ClientBase.cs'不存在。

Looking in script documents for 'C:\\Build Agent\\vsts-agent-win7-x64-2.117.1_work\\1\\s\\ClientsShared\\Class\\ClientBase.cs'... 查看'C:\\ Build Agent \\ vsts-agent-win7-x64-2.117.1_work \\ 1 \\ s \\ ClientsShared \\ Class \\ ClientBase.cs'的脚本文档...

Looking in the projects for 'C:\\Build Agent\\vsts-agent-win7-x64-2.117.1_work\\1\\s\\ClientsShared\\Class\\ClientBase.cs'. 查看'C:\\ Build Agent \\ vsts-agent-win7-x64-2.117.1_work \\ 1 \\ s \\ ClientsShared \\ Class \\ ClientBase.cs'的项目。

The file was not found in a project. 在项目中找不到该文件。

Looking for source using source server... 使用源服务器寻找源代码...

The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: C:\\Build Agent\\vsts-agent-win7-x64-2.117.1_work\\1\\s\\ClientsShared\\Class\\ClientBase.cs. 活动解决方案的调试源文件设置表明调试器不会要求用户查找文件:C:\\ Build Agent \\ vsts-agent-win7-x64-2.117.1_work \\ 1 \\ s \\ ClientsShared \\ Class \\ ClientBase的.cs。

The debugger could not locate the source file 'C:\\Build Agent\\vsts-agent-win7-x64-2.117.1_work\\1\\s\\ClientsShared\\Class\\ClientBase.cs'. 调试器找不到源文件'C:\\ Build Agent \\ vsts-agent-win7-x64-2.117.1_work \\ 1 \\ s \\ ClientsShared \\ Class \\ ClientBase.cs'。

Why is it looking for the source code on the Build Agent? 为什么要在Build Agent上寻找源代码? Should this not be stored within the PDB on the Symbol Server? 这不应存储在符号服务器上的PDB中吗?

What's likely happening is that the PDB file that you have added to your NuGet package is not the indexed file. 可能发生的是您添加到NuGet包中的PDB文件不是索引文件。 It is the original file as built by MSBuild. 它是由MSBuild构建的原始文件。

Are you using TeamCity? 你在使用TeamCity吗? Do you have only one build configuration? 你只有一个构建配置吗? If so, then this is certainly the case. 如果是这样,那肯定是这样的。

TeamCity indexes any PDB files that are created as Artifacts (assuming that you have the plugin installed). TeamCity索引任何创建为Artifacts的PDB文件(假设您已安装插件 )。 Here's the catch: indexing your PDB means modifying your PDB. 这是一个问题:索引PDB意味着修改您的PDB。 The modified PDB will be found in the build artifacts. 修改后的PDB将在构建工件中找到。 Since there is no point during your build that the modified (indexed) PDB will be available, you have to split this into two configurations. 由于在构建期间没有任何意义,修改(索引)的PDB将可用,您必须将其拆分为两个配置。

The Build Configuration 构建配置

Create a build configuration called Build and edit the configuration settings. 创建名为Build的构建配置并编辑配置设置。 Look at General Settings. 查看常规设置。 Artifact Paths lists the files that will be output from your build. 工件路径列出将从您的构建输出的文件。

This text box lists a series of rules: copy files matching this pattern to artifacts at that path. 此文本框列出了一系列规则:将与模式匹配的文件复制到路径中的工件。 You want to add rules to copy your dll, pdb, sln, csproj, nuspec, and packages.config files to artifacts using the correct relative structure. 您希望添加规则以使用正确的相对结构将dll,pdb,sln,csproj,nuspec和packages.config文件复制到工件。 You should end up with something like this: 你应该得到这样的东西:

MyProject.sln
MyProject/bin/Release/MyProject.pdb => MyProject/bin/Release
MyProject/bin/Release/MyProject.dll => MyProject/bin/Release
MyProject/MyProject.csproj => MyProject
MyProject/MyProject.nuspec => MyProject
MyProject/packages.config => MyProject

Run this build and verify that you get the expected artifacts. 运行此构建并验证您是否获得了预期的工件。 Check the Build Log and make sure that it includes the steps “Indexing symbol sources” and “Publishing symbol sources”. 检查构建日志并确保它包含“索引符号源”和“发布符号源”步骤。 Then click on the Artifacts tab of the successful build, and these six files should be listed, and in the correct directory structure. 然后单击成功构建的Artifacts选项卡,应列出这六个文件,并使用正确的目录结构。

The NuGet Configuration NuGet配置

Since TeamCity modifies your PDB when it indexes it, you cannot generate the NuGet package in the Build configuration. 由于TeamCity在对其进行索引时修改了PDB,因此无法在Build配置中生成NuGet包。 You need a second configuration. 您需要第二次配置。 This one we will call “NuGet”. 这个我们称之为“NuGet”。

Create a new build configuration called NuGet and edit the configuration settings. 创建名为NuGet的新构建配置并编辑配置设置。 Look at Dependencies, and add a new Artifact Dependency. 查看依赖项,并添加一个新的工件依赖项。 This should depend upon the Build configuration and get artifacts from the last successful build. 这应该取决于Build配置并从上次成功构建中获取工件。 Bring in all of the files that we output from the Build configuration: 引入我们从Build配置输出的所有文件:

**/*

Create a Build Step called "NuGet Install". 创建一个名为“NuGet Install”的构建步骤。 This should be a "NuGet Install" step to restore all of your dependencies. 这应该是一个“NuGet Install”步骤来恢复所有依赖项。 Enter the name of your *.sln file. 输入* .sln文件的名称。

Create a second Build Step called "NuGet Pack". 创建第二个名为“NuGet Pack”的构建步骤。 This should be a “NuGet Pack” step. 这应该是“NuGet Pack”步骤。 The specification file will actually be your csproj, not your nuspec! 规范文件实际上是你的csproj,而不是你的nuspec! Just give the full path, such as MyProject/MyProject.csproj. 只需提供完整路径,例如MyProject / MyProject.csproj。 Set the output directory to “Packages” and check “Publish created packages to build artifacts”. 将输出目录设置为“Packages”并选中“发布创建的包以构建工件”。

The NuGet Specification NuGet规范

To complete the picture, you need to be sure that the *.nuspec file includes the PDB file. 要完成图片,您需要确保* .nuspec文件包含PDB文件。 You can do this by listing the DLL and PDB as files within the *.nuspec. 您可以通过将DLL和PDB列为* .nuspec中的文件来完成此操作。 Add a section below (not inside of it) and list both of those files. 在下面添加一个部分(不在其中)并列出这两个文件。 It should look something like this: 它应该看起来像这样:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <copyright>Copyright 2018</copyright>
  </metadata>
  <files>
    <file src="bin\Release\MyProject.dll" target="lib\net461" />
    <file src="bin\Release\MyProject.pdb" target="lib\net461" />
  </files>
</package>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM