### Install GitInfo via NuGet Package Manager Source: https://github.com/devlooped/gitinfo/blob/main/readme.md This command installs the GitInfo NuGet package using the Package Manager Console in Visual Studio. This package provides Git information to MSBuild, C#, and VB projects. ```pwsh PM> Install-Package GitInfo ``` -------------------------------- ### Custom Assembly Version Attributes in F# Source: https://github.com/devlooped/gitinfo/blob/main/readme.md Provides F# code examples for manually setting assembly version attributes using GitInfo constants. This includes `AssemblyVersion`, `AssemblyFileVersion`, and `AssemblyInformationalVersion`. ```fsharp module AssemblyInfo open System.Reflection [] [] [] do () ``` -------------------------------- ### Custom Assembly Version Attributes in C# Source: https://github.com/devlooped/gitinfo/blob/main/readme.md Provides C# code examples for manually setting assembly version attributes using GitInfo constants. This includes `AssemblyVersion`, `AssemblyFileVersion`, and `AssemblyInformationalVersion`. ```csharp [assembly: AssemblyVersion(ThisAssembly.Git.BaseVersion.Major + "." + ThisAssembly.Git.BaseVersion.Minor + "." + ThisAssembly.Git.BaseVersion.Patch)] [assembly: AssemblyFileVersion(ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.SemVer.Patch)] [assembly: AssemblyInformationalVersion( ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.Commits + "-" + ThisAssembly.Git.Branch + "+" + ThisAssembly.Git.Commit)] ``` -------------------------------- ### Custom Assembly Version Attributes in VB.NET Source: https://github.com/devlooped/gitinfo/blob/main/readme.md Provides VB.NET code examples for manually setting assembly version attributes using GitInfo constants. This includes `AssemblyVersion`, `AssemblyFileVersion`, and `AssemblyInformationalVersion`. ```vbnet ``` -------------------------------- ### Accessing Git Commit Information in C# Source: https://github.com/devlooped/gitinfo/blob/main/readme.md Demonstrates how to access Git commit information directly from a C# project after installing the GitInfo package. This information is available as constants within the `ThisAssembly.Git` static class. ```csharp Console.WriteLine(ThisAssembly.Git.Commit); ``` -------------------------------- ### Custom Versioning Logic with MSBuild Target Source: https://github.com/devlooped/gitinfo/blob/main/readme.md Demonstrates how to define a custom MSBuild target that depends on `GitVersion` to populate versioning properties like `Version`, `PackageVersion`, and source control identifiers. ```xml false $(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)+$(GitBranch).$(GitCommit) $(Version) $(GitBranch) $(GitCommit) $(GitBranch) $(GitCommit) ``` -------------------------------- ### MSBuild Targets File for GitInfo Integration Source: https://github.com/devlooped/gitinfo/blob/main/readme.md This MSBuild .targets file is part of the GitInfo NuGet package and handles the integration of Git information into the build process without custom tasks. It defines build inputs and outputs for efficient caching. ```xml $(BuildDependsOn);GenerateGitInfo ``` -------------------------------- ### F# Template for Git Information Generation Source: https://github.com/devlooped/gitinfo/blob/main/readme.md This F# template file is used by the GitInfo NuGet package to generate code that embeds Git information into the assembly. It offers an alternative to C# for F# projects. ```fsharp // This is a placeholder for the actual F# template content. // The file GitInfo.fs.pp contains the actual template. // Example placeholder: module GitInfo let majorMinorPatch = "0.1.0" let sha = "abcdef1234567890" ``` -------------------------------- ### Enabling GitInfo Generation in MSBuild Source: https://github.com/devlooped/gitinfo/blob/main/src/GitInfo/readme.txt Shows how to enable the generation of the `ThisAssembly` class and `AssemblyMetadata` attributes for Git information within an MSBuild project file (e.g., `.csproj`). Both `GitThisAssembly` and `GitThisAssemblyMetadata` properties need to be set to 'true'. ```xml true true ``` -------------------------------- ### VB Template for Git Information Generation Source: https://github.com/devlooped/gitinfo/blob/main/readme.md This VB template file is used by the GitInfo NuGet package to generate code that embeds Git information into the assembly. It provides support for Visual Basic projects. ```vbnet ' This is a placeholder for the actual VB template content. ' The file GitInfo.vb.pp contains the actual template. ' Example placeholder: Public Module GitInfo Public Const MajorMinorPatch As String = "0.1.0" Public Const Sha As String = "abcdef1234567890" End Module ``` -------------------------------- ### Accessing Git Information in C# Code Source: https://github.com/devlooped/gitinfo/blob/main/src/GitInfo/readme.txt Demonstrates how to access Git information programmatically from C# code. The generated constants allow constructing version attributes dynamically. This requires the `GitThisAssembly` MSBuild property to be set to 'true'. ```csharp [assembly: AssemblyVersion (ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.SemVer.Patch)] [assembly: AssemblyInformationalVersion ( ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.SemVer.Patch + "-" + ThisAssembly.Git.Branch + "+" + ThisAssembly.Git.Commit)] // i..e ^: 1.0.2-main+c218617 ``` -------------------------------- ### Code Constants for Git Information (C#, F#, VB) Source: https://github.com/devlooped/gitinfo/blob/main/readme.md For C#, F#, and VB.NET projects, GitInfo generates constants that allow you to access Git repository information directly from your code. These constants mirror the MSBuild properties, providing easy access to details like commit hash, branch, and versioning. ```csharp ThisAssembly.Git.RepositoryUrl ThisAssembly.Git.Branch ThisAssembly.Git.Commit ThisAssembly.Git.Commits ThisAssembly.Git.Tag ThisAssembly.Git.BaseTag ThisAssembly.Git.BaseVersion.Major ThisAssembly.Git.BaseVersion.Minor ThisAssembly.Git.BaseVersion.Patch ThisAssembly.Git.SemVer.Major ThisAssembly.Git.SemVer.Minor ThisAssembly.Git.SemVer.Patch ThisAssembly.Git.SemVer.Label ThisAssembly.Git.SemVer.DashLabel ThisAssembly.Git.SemVer.Source ThisAssembly.Git.IsDirty ``` -------------------------------- ### Opting Out of Default Git Versioning in MSBuild Source: https://github.com/devlooped/gitinfo/blob/main/readme.md Shows how to disable GitInfo's automatic version property population by setting `GitVersion` to `false` in the project file. This allows for manual control over versioning. ```xml false ``` -------------------------------- ### C# Template for Git Information Generation Source: https://github.com/devlooped/gitinfo/blob/main/readme.md This C# template file is used by the GitInfo NuGet package to generate code that embeds Git information into the assembly. It allows for customization of how Git data is represented. ```csharp // This is a placeholder for the actual C# template content. // The file GitInfo.cs.pp contains the actual template. // Example placeholder: namespace GitInfo { public static class GitVersion { public const string MajorMinorPatch = "0.1.0"; public const string Sha = "abcdef1234567890"; } } ``` -------------------------------- ### Optional Assembly Metadata Embedding with GitInfo Source: https://github.com/devlooped/gitinfo/blob/main/readme.md This MSBuild .targets file demonstrates how to optionally embed Git information directly into the assembly's metadata using the GitInfo package. It provides specific properties to control this behavior. ```xml $(BuildDependsOn);EmbedGitInfoInMetadata ``` -------------------------------- ### MSBuild Properties for Customizing GitInfo Behavior Source: https://github.com/devlooped/gitinfo/blob/main/readme.md A comprehensive list of MSBuild properties available to customize the behavior of the GitInfo project. These properties allow fine-tuning of versioning formats, assembly metadata generation, namespace usage, and Git-specific options like remote name, branch handling, and tag filtering. ```plaintext $(GitVersion): set to 'false' to avoid setting Version and PackageVersion to a default version with format: $(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)+$(GitBranch).$(GitCommit) $(GitThisAssembly): set to 'false' to prevent assembly metadata and constants generation. $(GitThisAssemblyMetadata): set to 'false' to prevent assembly metadata generation only. Defaults to 'false'. If 'true', it will also provide assembly metadata attributes for each of the populated values. $(ThisAssemblyNamespace): allows overriding the namespace for the ThisAssembly class. Defaults to the global namespace. $(GitRemote): name of remote to get repository url for. Defaults to 'origin'. $(GitBranchCI): determines whether the branch name should be populated from default environment variables used by the CI system. Default to 'true'. $(GitDefaultBranch): determines the base branch used to calculate commits on top of current branch. Defaults to 'main'. $(GitVersionFile): determines the name of a file in the Git repository root used to provide the base version info. Defaults to 'GitInfo.txt'. $(GitCommitsRelativeTo): optionally specifies an alternative directory for counting commits on top of the base version. Defaults to the $(GitVersionFile) directory. $(GitCommitsIgnoreMerges): set to 'true' to ignore merge commits when calculating the number of commits. Defaults to 'false'. $(GitInfoReportImportance): allows rendering all the retrieved git information with the specified message importance ('high', 'normal' or 'low'). Defaults to 'low'. $(GitIgnoreBranchVersion) and $(GitIgnoreTagVersion): determines whether the branch and tags (if any) will be used to find a base version. Defaults to empty value (no ignoring). $(GitNameRevOptions): options passed to git name-rev when finding a branch name for a commit (Detached head). The default is '--refs=refs/heads/* --no-undefined --always' meaning branch names only, falling back to commit hash. For the legacy behavior where $(GitBranch) for detached head can also be a tag name, use '--refs=refs/*'. Refs can be included and excluded, see git name-rev docs. $(GitSkipCache): whether to cache the Git information determined in a previous build in a GitInfo.cache for performance reasons. Defaults to empty value (no ignoring). $(GitCachePath): where to cache the determined Git Information. Gives the chance to use a shared location for different projects. This can improve the overall build time. Has to end with a path seperator Defaults to empty value ('$(IntermediateOutputPath)'). $(GitTagRegex): regular expression used with git describe to filter the tags to consider for base version lookup. Defaults to * (all). $(GitBaseVersionRegex): regular expression used to match and validate valid base versions in branch, tag or file sources. By default, matches any string that *ends* in a valid SemVer2 string. Defaults to 'v?(?\d+)\.(?\d+)\.(?\d+)(?:\-(?