MSBuild target for assembly build-time generation
$ dotnet add package NetLah.AssemblyInfo.BuildTime.TargetMSBuild target for assembly build-time generation.
<ItemGroup>
<PackageReference Include="NetLah.Abstractions" Version="0.2.0" />
<PackageReference Include="NetLah.AssemblyInfo.BuildTime.Target" Version="0.2.0" PrivateAssets="All" />
</ItemGroup>
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
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:
AssemblyTitle:NetLah.Abstractions
Version:0.2.0-rc2.2 BuildTime:2021-11-08T21:26:28+08:00; Framework:.NETStandard,Version=v2.0
var appInfo = ApplicationInfo.Initialize(null);
Console.WriteLine($"AppTitle:{appInfo.Title}");
Console.WriteLine($"Version:{appInfo.InformationalVersion} BuildTime:{appInfo.BuildTimestampLocal};Framework:{appInfo.FrameworkName}");
Output:
AppTitle:SampleApp
Version:0.2.0-rc2.2 BuildTime:2021-11-08T21:26:56+08:00; Framework:.NETCoreApp,Version=v6.0
Directory.Build.targets to declare build date time attribute to all projects inside the solutionNetLah.AssemblyInfo.BuildTime.Target<ItemGroup>
<PackageReference Update="NetLah.Abstractions" Version="0.2.0" />
<PackageReference Update="NetLah.AssemblyInfo.BuildTime.Target" Version="0.2.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="NetLah.Abstractions" Version="0.2.0" />
<PackageReference Include="NetLah.AssemblyInfo.BuildTime.Target" Version="0.2.0" PrivateAssets="All" />
</ItemGroup>