How to include commit URL in nuget package description
It's quite helpful to include a direct link to the source code 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, 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:
1
<Target Name="UpdatePackageMetadata"
2
BeforeTargets="PrepareForBuild;GetAssemblyVersion;GenerateNuspec;Pack"
3
Condition="'$(RepositoryUrl)' != '' And '$(SourceRevisionId)' != ''">
4
<PropertyGroup>
5
<Description>
6
$(Description)
7
8
Built from $(RepositoryUrl)/tree/$(SourceRevisionId.Substring(0, 9))
9
</Description>
10
<!-- Update nuspec properties too -->
11
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
12
<PackageDescription> $(Description)</PackageDescription>
13
</PropertyGroup>
14
</Target>
Copied!
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 packages.
If you're using GitInfo instead, you'll have to populate the RepositoryUrl yourself, and replace SourceRevisionId with GitSha.
Last modified 1mo ago
Copy link