GitInfo 3.3.5
dotnet add package GitInfo --version 3.3.5
NuGet\Install-Package GitInfo -Version 3.3.5
<PackageReference Include="GitInfo" Version="3.3.5"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add GitInfo --version 3.3.5
#r "nuget: GitInfo, 3.3.5"
// Install GitInfo as a Cake Addin #addin nuget:?package=GitInfo&version=3.3.5 // Install GitInfo as a Cake Tool #tool nuget:?package=GitInfo&version=3.3.5
GitInfo
来自 MSBuild、C# 和 VB 的 Git 信息
从 MSBuild 和代码中检索 Git 信息的一种新颖且透明的方法,无需使用任何自定义任务或编译代码和工具,隐藏设置、格式化字符串等。
用法
通过 NuGet 安装
PM> Install-Package GitInfo
默认情况下,如果包含的项目是 C#、F# 或 VB 项目,编译时生成的源文件将包含所有 Git 信息,可以在程序集的任何地方访问,如 ThisAssembly(部分)类别及其嵌套 Git 静态类别中的常量。
Console.WriteLine(ThisAssembly.Git.Commit);
注意:您可能需要关闭并重新打开解决方案,以便 Visual Studio 在安装包后第一次刷新 intellisense 并显示 ThisAssembly 类型。
默认情况下,GitInfo 还将设置 $(Version)
和 $(PackageVersion)
,.NET SDK 使用这些值推导 AssemblyInfo、FileVersion 和 InformationalVersion 值,以及用于打包。此默认版本格式化为以下已填充的 MSBuild 属性:$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)+$(GitBranch).$(GitCommit)
。
因此,在安装和构建/打包后,您将获得一些版本。
或者,您可以通过在项目文件中将 GitVersion=false
设置为退出默认版本控制,如果您只想利用 Git 信息和/或版本属性/常量。
<PropertyGroup>
<GitVersion>false</GitVersion>
</PropertyGroup>
这允许您使用提供的常量构建任何版本的属性,使用任何信息,无需设置、格式化字符串或任何东西,只需纯代码。
C#
[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)]
F#
module AssemblyInfo
open System.Reflection
[<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)>]
do ()
VB
<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)>
注意:当您自定义程序集版本属性时,需要关闭 .NET SDK 中对应的程序集版本属性生成,通过设置相关属性为 false:
GenerateAssemblyVersionAttribute
、GenerateAssemblyFileVersionAttribute
和GenerateAssemblyInformationalVersionAttribute
。
MSBuild
<PropertyGroup>
<GitVersion>false</GitVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GitInfo" PrivateAssets="all" />
</ItemGroup>
<Target Name="PopulateInfo" DependsOnTargets="GitVersion" BeforeTargets="GetAssemblyVersion;GenerateNuspec;GetPackageContents">
<PropertyGroup>
<Version>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)+$(GitBranch).$(GitCommit)</Version>
<PackageVersion>$(Version)</PackageVersion>
<RepositoryBranch>$(GitBranch)</RepositoryBranch>
<RepositoryCommit>$(GitCommit)</RepositoryCommit>
<SourceRevisionId>$(GitBranch) $(GitCommit)</SourceRevisionId>
</PropertyGroup>
</Target>
注意:由于提供的属性是通过需要在它们可用之前运行的目标填充的,因此您不能在项目级别的 PropertyGroup 中使用 GitInfo 提供的属性。您只能在使用依赖于 GitInfo 相关目标的任何目标(通常是上述示例中的
GitVersion
,如果您消费了 SemVer 属性)时使用它们。
由于这些信息在构建项目时始终可用,因此您永远不会依赖于生成版本的 CI 构建脚本,并且您总能本地编译与 CI 服务器构建的同一版本的程序集。
您可以在GitInfo 宣布博客文章中了解更多关于该项目的信息。
详细说明
提供以下信息,可以直接从任何依赖于 GitInfo 目标的 MSBuild 目标使用
$(GitRepositoryUrl)
$(GitBranch)
$(GitCommit)
$(GitCommitDate)
$(GitCommits)
$(GitTag)
$(GitBaseTag)
$(GitBaseVersionMajor)
$(GitBaseVersionMinor)
$(GitBaseVersionPatch)
$(GitSemVerMajor)
$(GitSemVerMinor)
$(GitSemVerPatch)
$(GitSemVerLabel)
$(GitSemVerDashLabel)
$(GitSemVerSource)
$(GitIsDirty)
对于 C#、F# 和 VB,还生成了常量,以便可以从代码中访问相同的信息
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
可用的MSBuild 属性以自定义行为
$(GitVersion): set to 'false' to prevent setting Version
and PackageVersion.
$(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'.
$(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'.
$(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).
$(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)').
$(GitNameRevOptions): Options passed to git name-rev when finding
a branch name for the current commit (Detached head). The default is
'--refs=refs/heads/* --no-undefined --always'
meaning branch names only, falling back to commit hash.
For 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.
$(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?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^(?<LABEL>[\dA-Za-z\-\.]+)\-v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)$'
目标
- 无编译代码或工具 → 100% 透明度
- 通过 一个 NuGet 包 简单地添加/安装
- 无需学习格式字符串或设置
- 简单的、结构化的 .targets 文件,只包含纯 MSBuild 和无自定义任务
- 可选嵌入 Git 信息到程序集元数据中
- 可选使用 Git 信息构建任意程序集/文件的版本信息,既 在 C# 中,也 在 VB 中。
- 通过调整 C# 或 F# 或 VB 模板(包括在 NuGet 包 中)来修改/改进生成的代码
- 100% 支持增量构建和高性能(所有适当的输入/输出到位,Git 信息的智能缓存等)
赞助商
-
.NETStandard 2.0
- ThisAssembly.Constants (>= 1.4.1)
NuGet 包 (11)
显示依赖于 GitInfo 的前 5 个 NuGet 包
包 | 下载 |
---|---|
Aqovia.PactProducerVerifier.AspNetCore
Pact Producer Test for aspnet core sites |
|
PH.RollingZipRotatorLog4net
A netstandard2.0 Zip utility to perform a very simple log4net file rotation. The code perform a zip-compression on every log-rotated file and delete it, watching on log4net output directory reading settings of appenders. |
|
Zooqle.Net
A .NET Standard library for searching torrents on Zooqle. |
|
BizStream.NET.Sdk
Core build and release configuration for packages and libraries distributed by BizStream. |
|
SPLogging.Web
Web Log helper 用于帮助保存会话及其他日志数据。 |
Github存储库 (38)
显示依赖GitInfo排名前5的GitHub存储库。
存储库 | 星星数 |
---|---|
DevToys-app/DevToys
开发者瑞士军刀。
|
|
dotnet/maui
.NET MAUI 是 .NET 多平台应用程序界面,用于构建覆盖移动、平板电脑和桌面端的本机设备应用程序的框架。
|
|
gitextensions/gitextensions
Git Extensions 是一个独立UI工具,用于管理git存储库。它还与Windows资源管理器和Microsoft Visual Studio(2015/2017/2019)集成。
|
|
xamarin/Xamarin.Forms
Xamarin.Forms 现已不再受支持。请将您的应用程序迁移到 .NET MAUI。
|
|
EventStore/EventStore
EventStoreDB,一个事件本原数据库。专为事件归档、事件驱动和微服务架构设计。
|
版本 | 下载 | 最后更新 |
---|---|---|
3.3.5 | 58,826 | 5/13/2024 |
3.3.4 | 66,470 | 2/15/2024 |
3.3.3 | 289,223 | 8/30/2023 |
3.3.2 | 367 | 8/30/2023 |
3.3.1 | 15,357 | 8/11/2023 |
3.3.0 | 610 | 8/11/2023 |
3.2.0 | 4,838 | 8/11/2023 |
2.3.0 | 630,860 | 11/18/2022 |
2.2.1 | 11,158 | 11/16/2022 |
2.2.0 | 1,449,515 | 8/26/2021 |
2.1.2 | 1,105,685 | 9/24/2020 |
2.1.1 | 815 | 9/24/2020 |
2.0.40 | 2,104 | 9/24/2020 |
2.0.39 | 3,203 | 9/23/2020 |
2.0.38 | 1,471 | 9/21/2020 |
2.0.37 | 1,083 | 9/20/2020 |
2.0.36 | 737 | 9/20/2020 |
2.0.35 | 729 | 9/20/2020 |
2.0.34 | 8,459 | 9/11/2020 |
2.0.33 | 11,405 | 8/28/2020 |
2.0.32 | 685 | 8/28/2020 |
2.0.31 | 66,553 | 8/3/2020 |
2.0.30 | 14,739 | 7/27/2020 |
2.0.29 | 50,045 | 7/22/2020 |
2.0.28 | 706 | 7/22/2020 |
2.0.27 | 713 | 7/22/2020 |
2.0.26 | 443,345 | 12/16/2019 |
2.0.25 | 1,656 | 12/13/2019 |
2.0.21 | 90,187 | 10/15/2019 |
2.0.20 | 643,996 | 11/13/2018 |
2.0.19 | 11,752 | 11/2/2018 |
2.0.18 | 103,442 | 9/26/2018 |
2.0.17 | 20,885 | 9/10/2018 |
2.0.16 | 1,019 | 9/10/2018 |
2.0.15 | 60,123 | 8/14/2018 |
2.0.14 | 2,667 | 8/3/2018 |
2.0.11 | 340,449 | 6/1/2018 |
2.0.10 | 33,242 | 2/21/2018 |
2.0.9 | 1,425 | 2/20/2018 |
2.0.8 | 15,477 | 11/30/2017 |
2.0.7 | 7,388 | 11/30/2017 |
2.0.6 | 18,621 | 10/22/2017 |
2.0.5 | 1,153 | 10/19/2017 |
2.0.3 | 8,455 | 10/18/2017 |
2.0.2 | 3,269 | 9/29/2017 |
2.0.1 | 89,055 | 8/24/2017 |
2.0.0 | 3,893 | 8/16/2017 |
1.1.72 | 2,128 | 8/7/2017 |
1.1.71 | 6,221 | 7/10/2017 |
1.1.70 | 1,118 | 7/10/2017 |
1.1.68 | 1,296 | 7/7/2017 |
1.1.67 | 1,415 | 7/4/2017 |
1.1.66 | 1,533 | 6/23/2017 |
1.1.65 | 1,418 | 6/15/2017 |
1.1.63 | 1,458 | 6/15/2017 |
1.1.62 | 2,583 | 6/4/2017 |
1.1.61 | 4,565 | 5/31/2017 |
1.1.60 | 1,939 | 5/16/2017 |
1.1.59 | 16,081 | 5/11/2017 |
1.1.58 | 1,411 | 5/5/2017 |
1.1.57 | 1,312 | 4/29/2017 |
1.1.56 | 1,137 | 4/28/2017 |
1.1.55 | 6,002 | 4/26/2017 |
1.1.54 | 1,143 | 4/26/2017 |
1.1.53 | 1,941 | 4/12/2017 |
1.1.48 | 3,481 | 2/10/2017 |
1.1.47 | 1,096 | 2/10/2017 |
1.1.45 | 2,749 | 1/27/2017 |
1.1.44 | 1,107 | 1/27/2017 |
1.1.43 | 1,207 | 1/25/2017 |
1.1.41 | 1,149 | 1/25/2017 |
1.1.40 | 1,514 | 1/6/2017 |
1.1.39 | 1,455 | 12/26/2016 |
1.1.38 | 1,929 | 12/26/2016 |
1.1.37 | 1,401 | 12/12/2016 |
1.1.35 | 2,158 | 11/29/2016 |
1.1.34 | 1,487 | 11/24/2016 |
1.1.31 | 1,883 | 9/13/2016 |
1.1.30 | 1,194 | 9/13/2016 |
1.1.29 | 1,832 | 9/3/2016 |
1.1.28 | 2,331 | 8/10/2016 |
1.1.27 | 1,268 | 8/8/2016 |
1.1.26 | 1,159 | 8/8/2016 |
1.1.25 | 2,783 | 7/28/2016 |
1.1.24 | 1,433 | 7/28/2016 |
1.1.23 | 1,439 | 7/28/2016 |
1.1.22 | 1,522 | 7/28/2016 |
1.1.20 | 2,201 | 6/4/2016 |
1.1.19 | 1,283 | 5/29/2016 |
1.1.17 | 1,188 | 5/26/2016 |
1.1.15 | 3,169 | 5/23/2016 |
1.1.14 | 2,371 | 5/22/2016 |
1.1.13 | 1,279 | 5/19/2016 |
1.1.12 | 3,341 | 4/24/2016 |
1.1.10 | 1,378 | 4/8/2016 |
1.1.9 | 1,232 | 3/31/2016 |
1.1.8 | 1,182 | 3/31/2016 |
1.1.7 | 1,183 | 3/31/2016 |
1.1.5 | 1,722 | 3/16/2016 |
1.1.4 | 1,192 | 3/16/2016 |
1.1.2 | 1,239 | 3/14/2016 |
1.1.1 | 1,819 | 3/12/2016 |
1.1.0 | 1,296 | 3/11/2016 |
1.0.64-pre | 886 | 3/12/2016 |
1.0.63-pre | 943 | 3/12/2016 |
1.0.62-pre | 1,041 | 3/12/2016 |
1.0.61-pre | 1,046 | 3/12/2016 |
1.0.60-pre | 924 | 3/11/2016 |
1.0.59-pre | 1,041 | 3/11/2016 |
1.0.58-pre | 917 | 3/11/2016 |
1.0.56-pre | 3,205 | 1/9/2016 |
1.0.55-pre | 1,814 | 1/7/2016 |
1.0.54-pre | 1,560 | 12/14/2015 |
1.0.53-pre | 1,049 | 12/10/2015 |
1.0.52-pre | 1,276 | 12/10/2015 |
1.0.51-pre | 1,045 | 12/10/2015 |
1.0.50-pre | 1,081 | 12/9/2015 |
1.0.49-pre | 2,760 | 10/5/2015 |
1.0.48-pre | 1,273 | 10/3/2015 |
1.0.47-pre | 1,118 | 9/2/2015 |
1.0.46-pre | 967 | 9/2/2015 |
1.0.45-pre | 1,024 | 9/1/2015 |
1.0.44-pre | 984 | 9/1/2015 |
1.0.43-pre | 977 | 9/1/2015 |
1.0.42-pre | 987 | 8/18/2015 |
1.0.41-pre | 1,306 | 8/7/2015 |
1.0.40-pre | 1,023 | 7/19/2015 |
1.0.39-pre | 975 | 7/10/2015 |
1.0.38-pre | 993 | 6/26/2015 |
1.0.37-pre | 943 | 6/26/2015 |
1.0.36-pre | 957 | 6/26/2015 |
1.0.35-pre | 975 | 6/26/2015 |
1.0.34-pre | 987 | 6/24/2015 |
1.0.33-pre | 1,046 | 6/17/2015 |
1.0.31-pre | 1,009 | 6/16/2015 |
1.0.30-pre | 970 | 6/16/2015 |
1.0.29-pre | 957 | 6/16/2015 |
1.0.28-pre | 970 | 6/16/2015 |
1.0.27-pre | 981 | 6/16/2015 |
1.0.26-pre | 1,007 | 6/15/2015 |
1.0.25-pre | 988 | 6/14/2015 |
1.0.24-pre | 1,015 | 6/11/2015 |
1.0.23-pre | 966 | 6/8/2015 |
1.0.22-pre | 971 | 6/8/2015 |
1.0.21-pre | 978 | 6/8/2015 |
1.0.20-pre | 1,005 | 6/8/2015 |
1.0.19-pre | 974 | 6/8/2015 |
1.0.18-pre | 979 | 6/8/2015 |
1.0.16-pre | 983 | 6/5/2015 |
1.0.15-pre | 1,011 | 6/5/2015 |
1.0.14-pre | 1,038 | 6/4/2015 |
1.0.11-pre | 945 | 6/3/2015 |
1.0.10-pre | 996 | 6/3/2015 |
1.0.9-pre | 1,001 | 6/3/2015 |
1.0.8-pre | 969 | 6/3/2015 |
1.0.7-pre | 1,033 | 6/3/2015 |
1.0.6-pre | 958 | 6/3/2015 |
1.0.5-pre | 949 | 6/3/2015 |
1.0.4-pre | 988 | 6/3/2015 |
1.0.3-pre | 967 | 6/3/2015 |
1.0.1-pre | 986 | 6/3/2015 |
1.0.0 | 1,436 | 2/22/2016 |
1.0.0-pre | 955 | 5/26/2015 |
0.0.196 | 609 | 10/14/2020 |
0.0.195 | 617 | 10/5/2020 |
0.0.194 | 6,995 | 9/24/2020 |