1

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?

Max951
  • 51
  • 4

2 Answers2

0

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.

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
  • Thank you for your answer. This is working only on Windows. May this is not supported right now? https://developercommunity.visualstudio.com/t/step-into-debugging-not-working-for-nuget-packages/864957 – Max951 Oct 30 '21 at 17:18
  • @Max951 - Just to make sure we are communicating: did you try **exactly** what I show? All 3 lines inside the PropertyGroup? The point of that approach, as described in the original comment, is that it does not require a separate file. From TysonMN: "Using all three together creates a DLL containing the binary code, the debug symbols, and the source code." What you linked, describes having a separate symbols file. – ToolmakerSteve Nov 02 '21 at 23:50
0

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

Adrain
  • 1,946
  • 1
  • 3
  • 7
  • Source link is not working in Visual Studion for Mac. I have done all like described in this article https://github.com/dotnet/sourcelink/blob/main/README.md. But debuging working only in Visual Studio 2019. Accordin this article https://developercommunity.visualstudio.com/t/step-into-debugging-not-working-for-nuget-packages/864957 Visual Studio for Mac doesn't support this feature. Can you give me real working example of csproj file of library that allows debugging in Visual Studio for Mac? – Max951 Nov 01 '21 at 06:07
  • How is not working? – Adrain Nov 01 '21 at 09:49
  • "Step into" sometimes ignored source link, sometimes propose me to download source file and when I'm trying to download it instead of the class code, I saw the html page source code of my gitlab's login page – Max951 Nov 01 '21 at 13:01
  • what is your vs for mac version and can you download the package and add it in your project? – Adrain Nov 02 '21 at 08:54
  • 1
    Is your source code publicly available? It sounds like your code requires authentication to download. Whilst source link is supported for Visual Studio for Mac, it only works with source code that can be downloaded without authentication. For example, you can step into Roslyn's source code, which has source link enabled, however Roslyn is publicly available on GitHub. – Matt Ward Nov 02 '21 at 23:29