1

I have a simple Blazor WASM app. I would like to show build date (and time) to users for debugging purposes. Just string in left down corner of the footer...

Obviously I would like to do this automatically. Where, when and how to store the datetime to be displayed in razor file?

Alamakanambra
  • 5,845
  • 3
  • 36
  • 43

2 Answers2

2

For debugging purposes, you could use the AssemblyTitle (or any other attribute you like)

First you add it to your csproj file

<PropertyGroup>
  <AssemblyTitle Condition="'$(Configuration)' == 'debug'">My Assembly $([System.DateTime]::Now)</AssemblyTitle>
</PropertyGroup>

Then in your Blazor code (MainLayout seems a good choice) you can extract the value and display it:

<div class="info-panel">@BuildInfo</div>
@code {
  string BuildInfo;
#if DEBUG
  protected override void OnInitialized()
  {
    Assembly curAssembly = typeof(Program).Assembly;
    BuildInfo = $"{curAssembly.GetCustomAttributes(false).OfType<AssemblyTitleAttribute>().FirstOrDefault().Title}";
  }
#endif
}

If you don't like the idea of using an existing attribute, you could create a custom attribute - but that seems over the top to me.

Mister Magoo
  • 7,452
  • 1
  • 20
  • 35
1

You may find useful information in answers to the below question.

ASP.NET - show application build date/info at the bottom of the screen

DotNetDublin
  • 770
  • 1
  • 9
  • 23
  • I do not care much about getting the date. I just don't know how to create something (string with date) during build time and this something present in blazor app.. It is probably very simple, I am just missing correct terms I guess.. – Alamakanambra Mar 19 '21 at 09:28