9

我正在尝试让 SourceLink 与私有 NuGet 包一起使用。我正在运行一个 netcore2.1 Web 应用程序,它引用托管在我们的 Azure Devops NuGet 源上的 netstandard2.0 NuGet 包。

问题 1: Source Link 是否支持 .NET Standard 包?

我已按照此处指南中的说明进行操作https://docs.microsoft.com/en-us/azure/devops/artifacts/symbols/setting-up-github-sourcelinking?view=vsts,基本上是:

  1. 将索引源和发布符号包添加到我的 Azure Devops 构建。

  2. 在 Visual Studio 中,将我们的 VSTS 服务器添加为符号服务器

  3. 在 Visual Studio 中,启用源链接支持。我还尝试启用源服务器支持。

构建管道发布符号路径似乎正在工作 - 在我看到的日志中: Succeeded processing D:\a\1\s\src\MyCompany.Core.Services.SnapshotClient\bin\release\netstandard2.0\MyCompany.Core.Services.SnapshotClient.pdb:

当我开始调试我的应用程序时,我在 VS 输出窗口中看到一堆输出: 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\2.1.4\Microsoft.AspNetCore.Hosting.dll'. Cannot find or open the PDB file.

对于我的 NuGet 包,我看到“已加载符号”,这似乎很有希望。

FWIW 我没有看到 Visual Studio 提示“源链接将从 Internet 下载”。

当我调试并尝试进入我的 NuGet 包时,它只是跳过它。

然后我尝试了:

  1. 前往https://github.com/dotnet/sourcelink并按照他们的指示安装 Microsoft.SourceLink.Vsts.Git 包(问题 2是否有必要?)

  2. 当这不起作用时,我升级了我的应用程序中的每个该死的包,这迫使我安装 .NET Core SDK 2.1.403

  3. 在搜索GitHub 问题之后,尝试在我的 NuGet 包的 .csproj 中添加一些东西, <PublishRepositoryUrl>true</PublishRepositoryUrl> <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> 现在 <DebugType>portable</DebugType> <ci>true</ci> 我的 .nupkg 也包含 .pdb 文件,这些文件以前不存在。尽管如此,仍然不能帮助我进行调试。

  4. 从https://www.nuget.org/packages/sourcelink/安装 sourcelink cli 工具并sourcelink print-urls从我的 .nupkg 在 .pdb 上运行。看起来正确,我想?存在 URL。

  5. 在看到@mitchdenny的评论https://github.com/MicrosoftDocs/vsts-docs/issues/1336#issuecomment-414415049后禁用索引。还是不行。

现在我很困惑为什么它不起作用。

4

2 回答 2

12

我写了一篇完整的博客,介绍如何使用 .NET Core 和 AzureDevops 执行此操作,但这些步骤也适用于 .NET Standard 项目。

也就是说,您应该知道的 Microsoft 文档中缺少的一些关键要点是:

  • 项目的调试信息需要从“Portable”改为“Full”
  • AzureDevOps Nuget(恢复、构建、打包和推送)需要使用 .NET Core 任务。
  • .NET Core 构建任务应该有一个参数“--configuration”,它传入值“debug”。这样做会生成 .PDB 文件
  • .NET Core pack 任务应使用“custom”命令,自定义命令为“pack”并具有以下参数:“--include-symbols -v d”和传入值“debug”的“-c” ”。这样做会告诉 pack 命令将 .PDB 文件包含在包中。
于 2019-01-10T17:45:49.090 回答
4

Question 1: Does Source Link support .NET Standard packages?

Yes. I successfully built a .NET Standard 2.0 library on Azure DevOps Pipeline, after which it was pushed to our private Azure DevOps Artifacts NuGet feed. Then, in a local project, I was able to step into the library (Visual Studio prompted me with a pop-up about downloading remote source code).

Here are the changes I had to make in the library's .csproj file:

<PropertyGroup>
  <PublishRepositoryUrl>true</PublishRepositoryUrl>
  <EmbedUntrackedSources>true</EmbedUntrackedSources>
  <AllowedOutputExtensionsInPackageBuildOutputFolder>
    $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
  </AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
...
<ItemGroup>
  <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All"/>
</ItemGroup>

Question 2: is that [PackageReference to Microsoft.SourceLink.GitHub] necessary?

I'm not sure. The docs suggest it is. But I removed the reference, re-built on Azure DevOps, and was still able to step through the library. Perhaps it's necessary for different environments (I'm keeping it just in case).

FWIW:

  • I'm debugging using Visual Studio 15.8.9
  • My latest installed .NET Core SDK is 2.1.403
  • My library's consumer is a .NET Core 2.1 executable
  • I compiled my library using Cake, which I have call into dotnet msbuild
于 2018-11-15T19:39:14.180 回答