---
title: Embed Git Information in .NET Build Artifacts
description: >-
  Embed Git information in .NET build artifacts for containers, serverless, and
  host deployments.
breadcrumbs: >-
  Docs > Source Code Integration > Service Mapping for Source Code Integration >
  Embed Git Information in .NET Build Artifacts
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Embed Git Information in .NET Build Artifacts

## Overview{% #overview %}

To embed Git information in your .NET build artifacts, follow the instructions for your deployment model: Containers, Serverless, or Host.

## Prerequisites{% #prerequisites %}

- [Datadog Agent](https://docs.datadoghq.com/agent.md) v7.35.0 or later is required.
- The .NET client library version 2.24.1 or later is required.
- Ensure that your `.pdb` files are deployed alongside your .NET assemblies (`.dll` or `.exe`) in the same folder.

## Containers{% #containers %}

If you are using Docker containers, you have three options: using Docker, using Microsoft SourceLink, or configuring your application with `DD_GIT_*` environment variables.

{% collapsible-section %}
### Docker

You can embed git information in your Docker image using either build arguments with environment variables, or image labels.

###### Using build arguments and environment variables{% #using-build-arguments-and-environment-variables %}

1. Add the following lines to your application's Dockerfile:

   ```dockerfile
   ARG DD_GIT_REPOSITORY_URL
   ARG DD_GIT_COMMIT_SHA
   ENV DD_GIT_REPOSITORY_URL=${DD_GIT_REPOSITORY_URL} 
   ENV DD_GIT_COMMIT_SHA=${DD_GIT_COMMIT_SHA}
   ```

1. Add the following arguments to your Docker build command:

   ```shell
   docker build . \
    -t my-application \
    --build-arg DD_GIT_REPOSITORY_URL=<git-provider.example/me/my-repo> \
    --build-arg DD_GIT_COMMIT_SHA=$(git rev-parse HEAD)
   ```

###### Using image labels{% #using-image-labels %}

This approach requires Docker, or containerd >= 1.5.6. It doesn't support containers running on AWS Fargate.

Datadog can extract source code information directly from your images' Docker labels. During build time, follow the [Open Containers standard](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys) to add the git commit SHA and repository URL as Docker labels:

```shell
docker build . \
  -t my-application \
  --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
  --label org.opencontainers.image.source=$(git config --get remote.origin.url)
```

{% /collapsible-section %}

{% collapsible-section %}
### Microsoft SourceLink

If you are using [Microsoft SourceLink](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys), Datadog can extract the git commit SHA and repository URL from your .NET assembly.

1. Open your project's file (`.csproj`) in an IDE and add a reference to one of the following NuGet packages, depending on where your git repository is hosted:
| Provider            | Microsoft SourceLink                                                                                                    |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| GitHub              | [Microsoft.SourceLink.GitHub](https://www.nuget.org/packages/Microsoft.SourceLink.GitHub)                               |
| Bitbucket           | [Microsoft.SourceLink.Bitbucket.Git](https://www.nuget.org/packages/Microsoft.SourceLink.Bitbucket.Git)                 |
| GitLab              | [Microsoft.SourceLink.GitLab](https://www.nuget.org/packages/Microsoft.SourceLink.GitLab)                               |
| Azure DevOps        | [Microsoft.SourceLink.AzureRepos.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureRepos.Git)               |
| Azure DevOps Server | [Microsoft.SourceLink.AzureDevOpsServer.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureDevOpsServer.Git) |

{% /collapsible-section %}

{% collapsible-section %}
### `DD_GIT_*` environment variables

Configure your application with the `DD_GIT_*` environment variables:

```go
export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"
```

Replace `<commitSha>` with the commit SHA used to build your application. You can retrieve this by running `git rev-parse HEAD` at build time, and it needs to be passed into the runtime environment variables. Replace `<git-provider.example/me/my-repo>` with your repository URL.
{% /collapsible-section %}

## Serverless{% #serverless %}

If you are using Serverless, you have the following options depending on your serverless application's setup.

{% collapsible-section %}
### Datadog tooling

{% dl %}

{% dt %}
[Datadog CLI tool](https://www.nuget.org/packages/Microsoft.SourceLink.GitHub)
{% /dt %}

{% dd %}
Use the `datadog-ci` client version 2.10.0 or later. You must run the CLI tool in the same directory as the code repository.
{% /dd %}

{% dt %}
[Datadog Serverless Plugin](https://www.nuget.org/packages/Microsoft.SourceLink.Bitbucket.Git)
{% /dt %}

{% dd %}
Use the plugin version 5.60.0 or later.
{% /dd %}

{% dt %}
[Datadog CDK Construct](https://www.nuget.org/packages/Microsoft.SourceLink.GitLab)
{% /dt %}

{% dd %}
Use the `datadog-cdk-constructs` version 0.8.5 or later for AWS CDK v1. Use the `datadog-cdk-constructs` version 1.4.0 or later for AWS CDK v2.
{% /dd %}

{% /dl %}

{% /collapsible-section %}

{% collapsible-section %}
### Microsoft SourceLink

If you are using [Microsoft SourceLink](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys), Datadog can extract the git commit SHA and repository URL from your .NET assembly.

1. Open your project's file (`.csproj`) in an IDE and add a reference to one of the following NuGet packages, depending on where your git repository is hosted:
| Provider            | Microsoft SourceLink                                                                                                    |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| GitHub              | [Microsoft.SourceLink.GitHub](https://www.nuget.org/packages/Microsoft.SourceLink.GitHub)                               |
| Bitbucket           | [Microsoft.SourceLink.Bitbucket.Git](https://www.nuget.org/packages/Microsoft.SourceLink.Bitbucket.Git)                 |
| GitLab              | [Microsoft.SourceLink.GitLab](https://www.nuget.org/packages/Microsoft.SourceLink.GitLab)                               |
| Azure DevOps        | [Microsoft.SourceLink.AzureRepos.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureRepos.Git)               |
| Azure DevOps Server | [Microsoft.SourceLink.AzureDevOpsServer.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureDevOpsServer.Git) |

{% /collapsible-section %}

{% collapsible-section %}
### `DD_GIT_*` environment variables

Configure your application with the `DD_GIT_*` environment variables:

```go
export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"
```

Replace `<commitSha>` with the commit SHA used to build your application. You can retrieve this by running `git rev-parse HEAD` at build time, and it needs to be passed into the runtime environment variables. Replace `<git-provider.example/me/my-repo>` with your repository URL.
{% /collapsible-section %}

## Host{% #host %}

If you are using a host, you have the following options: using Microsoft SourceLink or configuring your application with `DD_GIT_*` environment variables.

{% collapsible-section %}
### Microsoft SourceLink

If you are using [Microsoft SourceLink](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys), Datadog can extract the git commit SHA and repository URL from your .NET assembly.

1. Open your project's file (`.csproj`) in an IDE and add a reference to one of the following NuGet packages, depending on where your git repository is hosted:
| Provider            | Microsoft SourceLink                                                                                                    |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| GitHub              | [Microsoft.SourceLink.GitHub](https://www.nuget.org/packages/Microsoft.SourceLink.GitHub)                               |
| Bitbucket           | [Microsoft.SourceLink.Bitbucket.Git](https://www.nuget.org/packages/Microsoft.SourceLink.Bitbucket.Git)                 |
| GitLab              | [Microsoft.SourceLink.GitLab](https://www.nuget.org/packages/Microsoft.SourceLink.GitLab)                               |
| Azure DevOps        | [Microsoft.SourceLink.AzureRepos.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureRepos.Git)               |
| Azure DevOps Server | [Microsoft.SourceLink.AzureDevOpsServer.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureDevOpsServer.Git) |

{% /collapsible-section %}

{% collapsible-section %}
### `DD_GIT_*` environment variables

Configure your application with the `DD_GIT_*` environment variables:

```go
export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"
```

Replace `<commitSha>` with the commit SHA used to build your application. You can retrieve this by running `git rev-parse HEAD` at build time, and it needs to be passed into the runtime environment variables. Replace `<git-provider.example/me/my-repo>` with your repository URL.
{% /collapsible-section %}
