@@ -92,6 +92,75 @@ Which results in:
9292[ ![ Downloads] ( https://img.shields.io/nuget/dt/ThisAssembly.Git.svg?color=green )] ( https://www.nuget.org/packages/ThisAssembly.Git )
9393
9494<!-- include src/ThisAssembly.Git/readme.md#content -->
95+ <!-- #content -->
96+ This package generates a static ` ThisAssembly.Git ` class with constants
97+ for the following Git properties from the current project:
98+
99+ * Commit
100+ * Sha (first 9 chars from Commit)
101+ * Root (normalized to forward slashes)
102+ * Url (if PublishRepositoryUrl=true)
103+ * Branch (from CI environment variables)
104+
105+ This package relies on your project's installed
106+ [ Microsoft.SourceLink.* ] ( https://www.nuget.org/packages?q=Microsoft.SourceLink )
107+ package reference according to your specific Git-based source control server
108+ (such as GitHub, Azure DevOps, BitBucket, etc).
109+
110+ The ` Branch ` property is populated from supported CI environment variables
111+ for the currently supported CI systems: GitHub Actions, Azure DevOps,
112+ AppVeyor, TeamCity, Travis CI, Circle CI, GitLab CI, Buddy, and Jenkins.
113+
114+ Whenever the CI system provides a pull request number, the branch name is
115+ ` pr[NUMBER] ` , such as ` pr123 ` . This makes it easy to use it as a semver
116+ metadata label.
117+
118+ > Note: by default, the values of these constants are populated during
119+ "real" builds (that is, not IDE/design-time builds used to populate
120+ intellisense). This is to avoid negatively affecting the editor's
121+ performance. This means, however, that the properties will seem to
122+ always be empty when inspecting them in the IDE (although never at
123+ run-time). If you want to force population of these values for
124+ design-time builds, set the ` EnableSourceControlManagerQueries ` property to ` true ` .
125+ This property is defined and documented by
126+ [ dotnet/sourcelink] ( https://github.com/dotnet/sourcelink/blob/main/src/SourceLink.Common/build/Microsoft.SourceLink.Common.props#L14 ) .
127+
128+ At the MSBuild level, targets can take a dependency on the provided
129+ ` InitializeGitInformation ` target, which sets the equivalent properties
130+ named:
131+
132+ * RepositoryCommit
133+ * RepositorySha
134+ * RepositoryRoot
135+ * RepositoryUrl
136+ * RepositoryBranch
137+
138+ The names of these properties were chosen on purpose to match the
139+ properties used by [ nuget pack] ( https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target )
140+ and [ nugetizer] ( https://github.com/devlooped/nugetizer ) to populate
141+ the relevant package metadata.
142+
143+ So if you have a GitHub repository, installing these three packages
144+ will ensure you have the proper metadata out of the box and the simplest
145+ packaging experience possible:
146+
147+ ``` xml
148+ <Project Sdk =" Microsoft.NET.Sdk" >
149+ <PropertyGroup >
150+ <TargetFramework >netstandard2.0</TargetFramework >
151+ </PropertyGroup >
152+
153+ <ItemGroup >
154+ <PackageReference Include =" Microsoft.SourceLink.GitHub" />
155+ <PackageReference Include =" ThisAssembly.Git" />
156+ <PackageReference Include =" NuGetizer" />
157+ </ItemGroup >
158+ </Project >
159+ ```
160+
161+
162+ <!-- #content -->
163+ <!-- src/ThisAssembly.Git/readme.md#content -->
95164
96165## ThisAssembly.Metadata
97166
0 commit comments