embed git commit hash to assembly

https://stackoverflow.com/a/41200059/3782855

https://github.com/304NotModified/Fody.Stamp

 

.NET Revision Task for MSBuild

https://stackoverflow.com/a/59900651/3782855

https://github.com/ygoe/NetRevisionTask

Usage in C# source code

The following sample code from the AssemblyInfo.cs file would be resolved as described.

[assembly: AssemblyVersion("0.0")]
[assembly: AssemblyInformationalVersion("1.{c:15m:2013}-{chash:6}-{c:ymd}")]

Result:

[assembly: AssemblyVersion("1.93.42")]
[assembly: AssemblyInformationalVersion("1.93.42-45d4e3-20130401")]

Only C# and VB.NET projects and source files can be patched. Other source code language files are not found. This restriction should not apply to new-style simplified projects (like .NET Core).

MSBuild properties

Configuration of the version scheme is done through MSBuild properties defined in the project file to which the NuGet package was added. If you have multiple projects in your solution, you’d basically have to repeat these steps for each project, or you could factor them out into a separate .props file and import that into each project. This also applies to classic-style projects, even though editing the project file is a bit more involved.

 

 

Customize your build

MSBuild projects that use the standard build process (importing Microsoft.Common.props and Microsoft.Common.targets) have several extensibility hooks that you can use to customize your build process.

Directory.Build.props and Directory.Build.targets

Prior to MSBuild version 15, if you wanted to provide a new, custom property to projects in your solution, you had to manually add a reference to that property to every project file in the solution. Or, you had to define the property in a .props file and then explicitly import the .props file in every project in the solution, among other things.

 

However, now you can add a new property to every project in one step by defining it in a single file called Directory.Build.props in the root folder that contains your source. When MSBuild runs, Microsoft.Common.props searches your directory structure for the Directory.Build.props file (and Microsoft.Common.targets looks for Directory.Build.targets). If it finds one, it imports the property. Directory.Build.props is a user-defined file that provides customizations to projects under a directory.

 

实例

https://github.com/kerryjiang/SuperSocket/pull/344

 

NetRevisionTask

Dotted-decimal: Generates regular dotted version numbers with two segments. The first describes the days since the base year, the second the number of intervals since midnight (UTC). This scheme consists of multiple colon-separated values: interval length, base year.

The interval length is a number followed by “s” for seconds, “m” for minutes, “h” for hours, or “d” for days. Practical intervals are “15m” (2 digits), “2m” (3 digits).

A shortcut to the 15-minute interval is {dmin:<year>}.

{c:15m:2013}

PS D:\GitHub\ChuckLu\ConcurrentTestApp\ConcurrentTestApp\bin\Debug> [System.Diagnostics.FileVersionInfo]::GetVersionInfo("ConcurrentTestApp.exe").ProductVersion
1.2688.39-af72c5-20200512

2688是天数,39是interval

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(218)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示