【发布时间】:2021-03-19 08:12:33
【问题描述】:
我有一个简单的 Blazor WASM 应用程序。我想向用户显示构建日期(和时间)以进行调试。只需在页脚的左下角字符串...
显然我想自动执行此操作。 在哪里、何时以及如何存储要在 razor 文件中显示的日期时间?
【问题讨论】:
标签: c# asp.net-core blazor
我有一个简单的 Blazor WASM 应用程序。我想向用户显示构建日期(和时间)以进行调试。只需在页脚的左下角字符串...
显然我想自动执行此操作。 在哪里、何时以及如何存储要在 razor 文件中显示的日期时间?
【问题讨论】:
标签: c# asp.net-core blazor
出于调试目的,您可以使用 AssemblyTitle(或您喜欢的任何其他属性)
首先将其添加到您的 csproj 文件中
<PropertyGroup>
<AssemblyTitle Condition="'$(Configuration)' == 'debug'">My Assembly $([System.DateTime]::Now)</AssemblyTitle>
</PropertyGroup>
然后在您的 Blazor 代码中(MainLayout 似乎是一个不错的选择),您可以提取值并显示它:
<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
}
如果您不喜欢使用现有属性的想法,您可以创建一个自定义属性 - 但这对我来说似乎太过分了。
【讨论】:
您可以在以下问题的答案中找到有用的信息。
ASP.NET - show application build date/info at the bottom of the screen
【讨论】: