1

我的 gitlab 项目中托管了一些 nuget 包。而且我需要调试这个包并且不能在 Visual Studio for Mac 上这样做。这是我的 csproj 文件:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
    <!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
    <PublishRepositoryUrl>true</PublishRepositoryUrl>
    <!-- Optional: Embed source files that are not tracked by the source control manager in the PDB -->
    <EmbedUntrackedSources>true</EmbedUntrackedSources>
    <!-- Optional: Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
    <IncludeSymbols>true</IncludeSymbols>
    <!-- Recommended: Embed symbols containing Source Link in the main file (exe/dll) -->
    <DebugType>embedded</DebugType>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>
    <EmbedAllSources>true</EmbedAllSources>
    <PackageVersion>1.0.18.0</PackageVersion>
    <AssemblyVersion>1.0.18.0</AssemblyVersion>
    <FileVersion>1.0.18.0</FileVersion>
    <InformationalVersion>1.0.18.0</InformationalVersion>
    <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
  </PropertyGroup>

  <ItemGroup Condition="$(TargetFramework.StartsWith('netstandard2.0')) Or $(TargetFramework.StartsWith('netstandard2.1'))">
    <PackageReference Include="nlog" Version="4.6.2" />
    <PackageReference Include="System.Threading" Version="4.3.0" />
    <PackageReference Include="Microsoft.SourceLink.GitLab" Version="1.0.0" PrivateAssets="All"/>
    <Compile Include="ISynchronizationContext.cs" />
    <Compile Include="TaskExtensions.cs" />
    <Compile Include="AsyncAwaiter.cs" />
  </ItemGroup> 
  <ItemGroup Condition="$(TargetFramework.StartsWith('netcoreapp3.1'))">
    <PackageReference Include="Microsoft.SourceLink.GitLab" Version="1.0.0" PrivateAssets="All"/>
    <PackageReference Include="nlog" Version="4.6.2" />
    <PackageReference Include="System.Threading" Version="4.3.0" />
    <Compile Include="*.cs" />
  </ItemGroup>
  <PropertyGroup>
    <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
  </PropertyGroup>
</Project>

这是我的 .gitlab-ci.yml 部署部分:

deploy:
  stage: deploy
  script:
    - dotnet pack -c Release
    - dotnet nuget add source "$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name $CI_PROJECT_TITLE --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD --store-password-in-clear-text
    - dotnet nuget push "Source/bin/Release/*.nupkg" --source $CI_PROJECT_TITLE

调试在 Visual Studio 2019 中工作的 nuget 包,但在 Visual Studio for Mac 中不工作。在这篇文章中,我读到:

在 Visual Studio for Mac 中,尚不存在对符号服务器的支持,因此 Source Link 仅适用于包含其自己的调试符号的 NuGet 包。

我需要做什么才能在 Visual Studio for Mac 中调试我的 nuget 包?

4

2 回答 2

0

根据TysonMN 的评论,您的 .csproj 文件中的以下内容会将 PDB 符号和相关的源代码嵌入到 .nuget 中,以便 VS 可以找到它们:

<PropertyGroup>
  <DebugSymbols>True</DebugSymbols>
  <DebugType>Embedded</DebugType>
  <EmbedAllSources>True</EmbedAllSources>
</PropertyGroup>

未在 Mac 上测试 - 在评论中说明它是否有效。

于 2021-10-29T22:53:08.063 回答
0

您可以尝试使用Debugging NuGet packages with Source Link,根据 xamarin 文档:

源链接技术支持从 NuGet 对带有源文件链接的 .PDB 的 .NET 程序集进行源代码调试。源链接在开发人员创建他们的 NuGet 包并将源代码管理元数据嵌入程序集和包时执行。在 Visual Studio for Mac 中启用源链接后,IDE 将检测源文件是否可用于已安装的包。然后 Visual Studio for Mac 将提供下载它们,这将允许您逐步完成包代码。Source Link 还适用于 Xamarin 项目的 Mono 基类库代码,允许您也可以单步执行 .NET Framework 代码。Source Link 提供源代码控制元数据以创建出色的调试体验。

这是您的操作方法,您可以查看此文档https://docs.microsoft.com/en-us/visualstudio/mac/source-link?view=vsmac-2019

于 2021-11-01T01:54:42.667 回答