We are using Gitlab version 16.7 and I want to create a debug profile for my dotnet class library projects. But I couldn't find a detailed documentation on this topic. Below you can find my CI/CD settings. I couldn't find where to upload the .snupkg packages, I tried to upload it to "https://mygitlab.com/api/v4/projects/project-id/packages/nuget/symbolpackage" or I tried to upload it to "https://mygitlab.com/api/v4/projects/project-id/packages/nuget/index.json" but visual studio couldn't see the .snupkg file in both. How do you debug your projects with Gitlab?
stages:
- build
- deploy
image: mcr.microsoft.com/dotnet/sdk:7.0
variables:
OBJECTS_DIRECTORY: 'obj'
NUGET_PACKAGES_DIRECTORY: '.nuget'
SOURCE_CODE_PATH: '*/*/'
cache:
key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
paths:
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/project.assets.json'
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/*.csproj.nuget.*'
- '$NUGET_PACKAGES_DIRECTORY'
policy: pull-push
before_script:
- 'dotnet restore --packages $NUGET_PACKAGES_DIRECTORY'
- 'export VERSION_SUFFIX=beta$CI_PIPELINE_ID'
build:
stage: build
script:
- 'dotnet build --configuration Release'
deploy:
stage: deploy
script:
- 'dotnet pack -c Release /p:PackageVersion=1.0.0-$VERSION_SUFFIX --output $NUGET_PACKAGES_DIRECTORY --version-suffix $VERSION_SUFFIX --include-symbols -p:SymbolPackageFormat=snupkg'
- 'dotnet nuget add source "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text'
- 'dotnet nuget push $NUGET_PACKAGES_DIRECTORY/*.nupkg --source gitlab'
environment: production
Maybe because it is not yet officially supported.
See gitlab-org epic 10825:
A week ago (Dec. 19th, 2023), that epic says
To clarify:
The PDB (Program Database) files store debugging information for a given assembly (like a DLL or EXE). They contain data like function names, variable names, and line numbers that help debuggers correlate executable code with the source code that produced it.
The
.snupkgfiles are NuGet symbol packages. They are essentially containers for PDB files and possibly other related debugging information. They are designed to be uploaded to a symbol server or a NuGet feed, allowing debuggers to automatically fetch the corresponding PDB files when needed.In the context of GitLab, you have two different endpoints:
/packages/nuget/symbolfiles: This endpoint is likely meant for directly uploading PDB files.This assumes, as mentioned in the documentation, that you did enable the
nuget_symbol_server_enablednamespace setting with the GraphQL API./packages/nuget/symbolpackage: This endpoint is for uploading.snupkgpackages, which are the NuGet symbol packages containing the PDB files.Since you are working with
.snupkgfiles, you should use the "/packages/nuget/symbolpackage" endpoint. Your CI/CD pipeline needs to push these.snupkgpackages to this endpoint, allowing GitLab to serve as a symbol server.The relevant part of your CI/CD configuration for pushing the
.snupkgfiles will be:Make sure that the source 'gitlab' in the
dotnet nuget pushcommand is correctly configured to point to the/packages/nuget/symbolpackageendpoint on your GitLab instance.The presence of both
.nupkgand.snupkgfiles in your package registry is a good sign, indicating that your CI/CD pipeline is successfully uploading these packages..nupkgfiles are the NuGet packages containing your compiled code, resources, and metadata necessary for using your library..snupkgfiles are symbol packages contain the debugging symbols (PDB files) for your library. They are separate from the.nupkgfiles but are related to them.When you upload these packages to GitLab, they should be stored in the package registry, which serves as a repository for both types of files. Your pipeline already seems to be configured correctly for this.
That means:
You do not need to send the
.snupkgfiles to a different place: The fact that they are stored alongside the.nupkgfiles in the package registry is the intended behavior. That setup allows users and tools that consume your NuGet packages to also find and use the corresponding symbol packages for debugging.The
/packages/nuget/symbolpackageendpoint in GitLab is the correct destination for your.snupkgfiles. That is typically handled by your CI/CD pipeline script, as you have already set up with thedotnet nuget pushcommand.True: Since the
.snupkgendpoint is not currently functional for your needs, you will be focusing on the/packages/nuget/symbolfilesendpoint to transfer PDB files.So make sure your build process is creating PDB files. That is typically done by default in .NET projects, especially when building in the
Debugconfiguration. However, if you are building inReleasemode, make sure to include the necessary flags to generate PDB files. TheDebugTypeproperty in your.csprojfiles controls this.You need a script in your pipeline to identify and upload the PDB files to GitLab's
/packages/nuget/symbolfilesendpoint. That process might involve usingcurlor a similar tool to make HTTP requests to GitLab's API. Your script will need to include authentication against your GitLab instance, typically using a CI job token or a personal access token.That means your
deploystage might look like this:The
/p:DebugType=portableflag means portable PDB files are created. Portable PDBs are generally recommended for .NET Core and later projects.The
findcommand locates all PDB files in your output directory. Adjust the path if your PDB files are located elsewhere.The
curlcommand uploads each PDB file to the GitLab API. Replacehttps://mygitlab.comwith your actual GitLab instance URL, and make sure$CI_PROJECT_IDis correctly set in your CI environment. The script usesJOB-TOKENfor authentication. Make sure your CI job token has the necessary permissions to upload to the repository.The URL used in the
curlcommand might not be correct. Double-check the API endpoint provided by GitLab for uploading symbol files. Make sure it matches the one you are using in the script.And double-check that the
$CI_PROJECT_IDin your script does correspond to your project's ID in GitLab. A mismatch here could result in the endpoint not being found.Verify that the CI job token (
$CI_JOB_TOKEN) has the necessary permissions to upload files to the repository. If the token lacks the required privileges, it might lead to a404error.You can add debugging lines to help diagnose the issue (
curl --verbose, and echo lines):