Debug nuget packages on Visual Studio for Mac not working

598 Views Asked by At

I have some nuget package hosted in my gitlab project. And I need debug this package and can't do this on Visual Studio for Mac. Here is my csproj file:

<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>

this is my deploy part of .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

Debug nuget package working in Visual Studio 2019, but not working in Visual Studio for Mac. In this article I have read that:

In Visual Studio for Mac, support for symbol servers doesn’t exist yet, so Source Link only works with NuGet packages that contain their own debug symbols.

What I need to do to enable debugging my nuget package in Visual Studio for Mac?

2

There are 2 best solutions below

5
Adrain On BEST ANSWER

You can try use Debugging NuGet packages with Source Link,According to xamarin documents:

Source Link technology enables source code debugging of .NET assemblies from NuGet that ship .PDBs with links to source files. Source Link executes when developers create their NuGet package and embed source control metadata inside assemblies and the package. When Source Link is enabled in Visual Studio for Mac, the IDE will detect if source files are available for installed packages. Visual Studio for Mac will then offer to download them, which will allow you to step through the package code. Source Link also works with Mono Base Class Library code for Xamarin projects, allowing you to step into .NET Framework code as well. Source Link provides source control metadata to create a great debugging experience.

Here is how you do it, you could check this document https://learn.microsoft.com/en-us/visualstudio/mac/source-link?view=vsmac-2019

2
ToolmakerSteve On

According to this comment by TysonMN, the following in your .csproj file will embed both PDB symbols and associated source code into .nuget, such that VS can find them:

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

Not tested on Mac - say in comment whether it works or not.