https://github.com/netlah/abstractions
Classes for retrieving .NET assembly build time ApplicationInfo, AssemblyInfo
https://github.com/netlah/abstractions
application-info aspnetcore assembly assembly-build-datetime assembly-info build build-datetime diagnostics dotnet netcore
Last synced: 8 months ago
JSON representation
Classes for retrieving .NET assembly build time ApplicationInfo, AssemblyInfo
- Host: GitHub
- URL: https://github.com/netlah/abstractions
- Owner: NetLah
- License: mit
- Created: 2021-05-08T04:45:42.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T06:47:09.000Z (over 2 years ago)
- Last Synced: 2025-02-10T23:46:48.465Z (over 1 year ago)
- Topics: application-info, aspnetcore, assembly, assembly-build-datetime, assembly-info, build, build-datetime, diagnostics, dotnet, netcore
- Language: C#
- Homepage:
- Size: 117 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NetLah.Abstractions - .NET Library
[NetLah.Abstractions](https://www.nuget.org/packages/NetLah.Abstractions/) is .NET library of reusable classes for retrieving .NET assembly build time `ApplicationInfo`, `AssemblyInfo`.
[NetLah.AssemblyInfo.BuildTime.Target](https://www.nuget.org/packages/NetLah.AssemblyInfo.BuildTime.Target/) is MSBuild target for assembly build-time generation.
## Nuget package
[](https://www.nuget.org/packages/NetLah.Abstractions/)
[](https://www.nuget.org/packages/NetLah.AssemblyInfo.BuildTime.Target/)
## Build Status
[](https://actions-badge.atrox.dev/NetLah/abstractions/goto?ref=main)
## Getting started
This solution come from the idea of [Gérald Barré on Meziantou's blog Getting the date of build of a .NET assembly at runtime](https://www.meziantou.net/getting-the-date-of-build-of-a-dotnet-assembly-at-runtime.htm)
### 1. Add/Update PackageReference to .csproj
```xml
```
### 2. Output during build
```txt
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
SampleApp -> C:\Work\NetLah\abstractions\samples\SampleApp\bin\Debug\net6.0\SampleApp.dll
SampleApp [buildTime] := 2021-11-08T21:26:28 (net6.0)
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.84
```
### 2. Retrieve build datetime of assembly
```csharp
var asm = new AssemblyInfo(typeof(AssemblyInfo).Assembly);
Console.WriteLine($"AssemblyTitle:{asm.Title}");
Console.WriteLine($"Version:{asm.InformationalVersion} BuildTime:{asm.BuildTimestampLocal}; Framework:{asm.FrameworkName}");
```
The output:
```text
AssemblyTitle:NetLah.Abstractions
Version:0.2.0-rc2.2 BuildTime:2021-11-08T21:26:28+08:00; Framework:.NETStandard,Version=v2.0
```
### 3. Or Retrieve build datetime of entry assembly
```csharp
var appInfo = ApplicationInfo.Initialize(null);
Console.WriteLine($"AppTitle:{appInfo.Title}");
Console.WriteLine($"Version:{appInfo.InformationalVersion} BuildTime:{appInfo.BuildTimestampLocal};Framework:{appInfo.FrameworkName}");
```
Output:
```text
AppTitle:SampleApp
Version:0.2.0-rc2.2 BuildTime:2021-11-08T21:26:56+08:00; Framework:.NETCoreApp,Version=v6.0
```
### 4. Use `Directory.Build.targets` to declare build date time attribute to all projects inside the solution
- Set build date time to projects that already include packageReference `NetLah.AssemblyInfo.BuildTime.Target`
```xml
```
- Set build date time to all projects
```xml
```