[英]Display version, build date and environment of Blazor webassembly application
I am trying to display the version, build date and environment variable on the NavMenu of a Blazor Webassembly application.我正在尝试在 Blazor Webassembly 应用程序的 NavMenu 上显示版本、构建日期和环境变量。 Here is what i have tried but in vain这是我尝试过但徒劳无功
NavMenu.razor.cs NavMenu.razor.cs
protected static Version AppVersion => Assembly.GetExecutingAssembly().GetName().Version?? throw new NullReferenceException();
protected DateTime BuildDate => new DateTime(2000, 1, 1).AddDays(AppVersion.Build).AddSeconds(AppVersion.Revision * 2);
protected string DisplayEnvironment => Environment.GetEnvironmentVariable(EnvironmentVariableTarget.Process) ?? throw new NullReferenceException()
When i run the app i get null reference exception possibly on DisplayEnvironment property.当我运行该应用程序时,我可能会在 DisplayEnvironment 属性上收到 null 引用异常。 I would appreciate any help.我将不胜感激任何帮助。
According to this link , environment variables aren't available to Blazor WebAssembly.根据此链接,环境变量不适用于 Blazor WebAssembly。
You can obtain the app's environment in a component by injecting IWebAssemblyHostEnvironment and reading the Environment property.您可以通过注入IWebAssemblyHostEnvironment并读取Environment属性来获取组件中应用程序的环境。
@using Microsoft.AspNetCore.Components.WebAssembly.Hosting
@inject IWebAssemblyHostEnvironment HostEnvironment
<h1>Environment example</h1>
<p>Environment: @HostEnvironment.Environment</p>
Reference link: ASP.NET Core Blazor environments参考链接: ASP.NET Core Blazor环境
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.