> For the complete documentation index, see [llms.txt](https://til.cazzulino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.cazzulino.com/msbuild/how-to-include-commit-url-in-nuget-package-description.md).

# How to include commit URL in nuget package description

It's quite helpful to include a [direct link to the source code](https://www.nuget.org/packages/Microsoft.AspnetCore.Authorization) that produced a given package version, so your users can quickly see what's included (i.e. they may be tracking a bug fix).

If you are using [Microsoft.SourceLink](https://www.nuget.org/packages?q=Microsoft.SourceLink), you already have all the information you need automatically populated for you. The following target will update the description just before the nuget is produced:

```markup
  <Target Name="UpdatePackageMetadata" 
          BeforeTargets="PrepareForBuild;GetAssemblyVersion;GenerateNuspec;Pack"
          Condition="'$(RepositoryUrl)' != '' And '$(SourceRevisionId)' != ''">
    <PropertyGroup>
      <Description>
        $(Description)

        Built from $(RepositoryUrl)/tree/$(SourceRevisionId.Substring(0, 9))
      </Description>
      <!-- Update nuspec properties too -->
      <PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
      <PackageDescription> $(Description)</PackageDescription>
    </PropertyGroup>
  </Target>
```

This will result in a short-ish link (we trim it to 9 chars, which is the common short sha in Git) to the repo, similar to many [ASP.NET Core](https://www.nuget.org/packages/Microsoft.AspNetCore.Http/) [packages](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Core/).

If you're using [GitInfo](https://www.nuget.org/packages/GitInfo/) instead, you'll have to populate the `RepositoryUrl` yourself, and replace `SourceRevisionId` with `GitSha`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://til.cazzulino.com/msbuild/how-to-include-commit-url-in-nuget-package-description.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
