与Azure DevOps符号服务器的源链接 [英] Source Link with an Azure DevOps Symbol Server

查看:151
本文介绍了与Azure DevOps符号服务器的源链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Internet上有多种关于如何使用符号源文件和Source Link在Nuget包中进行调试的方法,但是说实话,很难理解对我来说是什么好方法.

我们有一台Azure DevOps服务器,在其上生成Nuget程序包,同时使用我们的构建管道中的Index Sources & Publish Symbols任务将.pdb文件发布到Azure DevOps Symbol Server,如下所示://docs.microsoft.com/zh-cn/azure/devops/pipelines/artifacts/symbols?view=azure-devops"rel =" noreferrer>在此处描述

我的项目"也引用了Microsoft.SourceLink.Vsts.Git.csproj文件中的这段代码

 <PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
 

我已经阅读了几篇博客文章,但是我最相信最新的消息来源当然是官方源链接Git存储库.

readme.md文件显示

通常不再建议在.nupkg中包含PDB,因为这会增加包的大小,从而为使用您的包的项目恢复时间,无论用户是否需要通过库的源代码进行调试

我同意这一点,这就是为什么我要使用Symbol Server而不在Nuget软件包中包含.pdb文件的原因.因此,请勿将我的问题标记为此副本的副本,因为接受的答案正是我不想做的.

自述文件还指出

.snupkg符号包有一些限制:

  • 它们当前不支持Windows PDB(由VC ++生成,或者不支持将构建属性DebugType设置为full的托管项目)
  • 他们要求该库由较新的C#/VB编译器(Visual Studio 2017 Update 9)构建.
  • 该程序包的使用者还需要Visual Studio 2017 Update 9调试器.
  • Azure DevOps Artifacts服务不支持.

所以至少我知道我不能使用它.

但是设置Source Link并使其正常工作的正确方法是什么?

当我调试测试控制台应用程序时,它成功地将.pdb文件下载到我的Symbols缓存文件夹中,但是如果我尝试使用F11插入来自Nuget软件包的代码,那将无法正常工作. (但是它进入了System.String.Concat,因为我的简单测试Nuget Package实际上是串联了一些字符串)

我尝试运行sourcelink test TestSourceLink.pdb,但得到了error: url hash does not match.我在此处中读到,sourcelink test是旧版内容,不支持对私有身份验证像我们这样的存储库.

使用浏览器,如果我访问sourcelink print-json TestSourceLink.pdb给出的URL,则可以看到最新的源代码.但是现在的问题是,为什么Visual Studio无法下载源代码?我已通过VS在此Azure DevOps服务器上进行身份验证,因为我能够安装来自该服务器的Nuget程序包.

这是我的调试设置:

非常感谢.我真的不知道这个难题的缺失之处是什么

解决方案

好,我应该阅读并遵循此答案在发布我的问题之前,因为这是难题的缺失部分.

我需要遵循.谢谢

:由于我为公司编写了文档,因此这里是:

摘要:

这需要两件事:

  • 可以访问项目的符号文件(.pdb),该文件是调试器使用的映射文件
  • 启用Source Link支持,以便Visual Studio知道在调试时应该在哪里下载源代码

设置:

Component的项目

对于您解决方案中的每个项目:

  1. 仅当您计划Nuget程序包的使用者使用Visual Studio 2017时.如果要在Visual Studio 2019中使用Source Link,则不需要此步骤:

    在Visual Studio中,右键单击您的项目-> Properties,然后转到Build -> Advanced,然后将Debugging InformationPortable(默认值)更改为Full

  2. 安装 Microsoft.SourceLink.AzureDevOpsServer.Git Nuget程序包

  3. 编辑.csproj文件,并在第一个PropertyGroup元素中包含以下代码:

  <PublishRepositoryUrl>true</PublishRepositoryUrl>
 <EmbedUntrackedSources>true</EmbedUntrackedSources>
 

Azure DevOps构建管道

  1. 创建一个名为BuildConfiguration的管道变量(如果尚不存在),并将其值设置为Debug

    • 将此变量用作.NET Core Build任务中的参数:--configuration $(BuildConfiguration)
    • 在您的.NET Core Pack任务中,在Configuration to Package字段中使用此变量:$(BuildConfiguration)
  2. 在管道的最后,您必须有一个任务Index Sources & Publish Symbols

    • Artifact name字段中,也必须使用BuildConfiguration变量:Symbols_$(BuildConfiguration)
  3. 当然,您还必须具有.NET Core Push任务,才能将Nuget程序包推送到Azure DevOps Nuget Feed

Visual Studio

  1. Tools -> Options -> Debugging -> Symbols单击New Azure DevOps Symbol Server Location...按钮并向服务器进行身份验证
    • 将缓存文件夹设置为方便的位置,例如C:\Symbols\.这是您所有.pdb文件的存储位置

  1. Tools -> Options -> Debugging -> Symbols单击Load only specified modules.您可以在此处指定要加载的DLL的符号文件.

    如果不执行此操作,并将默认值保留为Load all modules, unless excluded,则在调试模式下运行程序时,Visual Studio将花费很长时间加载所有内容.

    提示::要在调试时查看项目加载的所有DLL,请单击Debug -> Windows -> Modules.从这里您可以查看完整列表,选择多个列表,然后右键单击Copy Value -> Copy Name

  1. Tools -> Options -> Debugging -> General
    • 取消选中Enable Just My Code
    • 检查Enable source server support
    • 检查Enable Source Link Support

消费项目

如果要在Nuget软件包的代码中进行调试,请自然地按F11进入其中,Visual Studio会询问您是否同意从Azure DevOps存储库中下载源代码

There are several documented ways on internet on how to use Symbols Source files and Source Link to debug inside a Nuget Package but it's honestly hard to understand what is the good way for me.

We have an Azure DevOps Server on which we generate Nuget packages and at the same time publish the .pdb files to the Azure DevOps Symbol Server using an Index Sources & Publish Symbols task in our build pipelines as described here

My project' also has a reference to Microsoft.SourceLink.Vsts.Git and this code in the .csproj file

<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>

I've read several blog posts but the source I trust the most to be up to date is of course the official Source Link Git repository.

The readme.md file says

Including PDBs in the .nupkg is generally no longer recommended as it increases the size of the package and thus restore time for projects that consume your package, regardless of whether the user needs to debug through the source code of your library or not

I agree with that point that's why I want to use the Symbol Server, not to include the .pdb file in the Nuget Package. Therefore please don't flag my question as a duplicate of this one, because the accepted answer is exactly what I don't want to do.

The readme file also states that

.snupkg symbol packages have some limitations:

  • They do not currently support Windows PDBs (generated by VC++, or for managed projects that set build property DebugType to full)
  • They require the library to be built by newer C#/VB compiler (Visual Studio 2017 Update 9).
  • The consumer of the package also needs Visual Studio 2017 Update 9 debugger.
  • Not supported by Azure DevOps Artifacts service.

so at least I know I can't use that.

But what is the proper way to set Source Link up and working then?

When I debug my test console application it successfully downloads the .pdb file to my Symbols cache folder but if I try to step in the code coming from my Nuget Package using F11, it just doesn't work. (However it steps in System.String.Concat because my simple test Nuget Package is actually concatenating some strings)

I tried to run sourcelink test TestSourceLink.pdb but I get a error: url hash does not match. I read here that sourcelink test is a legacy thing and doesn't support authentication to private repositories like ours.

With my browser, if I visit the URL given by sourcelink print-json TestSourceLink.pdb I can see the latest source code. But now the question is, why is Visual Studio not able to download the source code? I'm authenticated to this Azure DevOps server in VS because I'm able to install Nuget Packages coming from this server.

Here are my debugging settings:

Thanks a lot. I really can't figure out what's the missing piece of this puzzle

解决方案

Well, I should have read and followed this answer before posting my question because this was the missing piece of the puzzle.

I needed to follow steps 5 and 6 of Eric's blog post but I actually didn't need to modify my pack command because I'm not including the .pdb file in the Nuget Package.

[EDIT 2]:

Note: So far I could only get this working if the Nuget Package is generated with the Debug Build Configuration. If you find a way to get Source Link working with a Release DLL inside the Nuget Package, please answer my other question. Thank you

[EDIT]: Since I wrote a documentation for my company, here it is:

Summary:

This requires two things:

  • Having access to the Symbol file of the project (.pdb) which is a mapping file used by the debugger
  • Enable Source Link support so Visual Studio knows where it should look to download the source code while debugging

Set Up:

Component's project

For each project in your solution:

  1. Only if you plan consumers of the Nuget package to use Visual Studio 2017. This step isn't required with you want to use Source Link with Visual Studio 2019:

    In Visual Studio, right click on your project -> Properties then go to Build -> Advanced and change the Debugging Information from Portable (default value) to Full

  2. Install the Microsoft.SourceLink.AzureDevOpsServer.Git Nuget Package

  3. Edit the .csproj file and include the following code in the first PropertyGroup element:

 <PublishRepositoryUrl>true</PublishRepositoryUrl>
 <EmbedUntrackedSources>true</EmbedUntrackedSources>

Azure DevOps build pipeline

  1. Create a pipeline variable called BuildConfiguration (if it doesn't exist already) and set the value to Debug

    • Use this variable as argument in your .NET Core Build task: --configuration $(BuildConfiguration)
    • In your .NET Core Pack task, use this variable in the Configuration to Package field: $(BuildConfiguration)
  2. At the end of your pipeline you must have a task Index Sources & Publish Symbols

    • In the Artifact name field, the BuildConfiguration variable must be used too: Symbols_$(BuildConfiguration)
  3. Of course you must also have a .NET Core Push task to push you Nuget package to your Azure DevOps Nuget Feed

Visual Studio

  1. Tools -> Options -> Debugging -> Symbols click on the New Azure DevOps Symbol Server Location... button and authenticate to the server
    • Set the cache folder to a convenient location like C:\Symbols\. This is where all your .pdb files will be stored

  1. Tools -> Options -> Debugging -> Symbols click on Load only specified modules. You can here specify the Symbol files of DLLs you want to load.

    If you don't do this and leave the default to Load all modules, unless excluded, Visual Studio will take a very long time to load everything when you run your program in debug mode.

    Tips : To see all the DLLs loaded by your project, when you're debugging, click on Debug -> Windows -> Modules. From here you can view the full list, select multiple and then right click Copy Value -> Copy Name

  1. Tools -> Options -> Debugging -> General
    • Uncheck Enable Just My Code
    • Check Enable source server support
    • Check Enable Source Link Support

Consuming project

When you want to debug inside the Nuget Package's code, naturally press F11 to step into it and Visual Studio will ask if you agree to download the source code from your Azure DevOps repository

这篇关于与Azure DevOps符号服务器的源链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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