从 .csproj 获取应用程序信息以用于自定义健康检查

Get application information from .csproj for use in custom health check

是否可以从 .csproj 文件获取数据以传递给 .NET 应用程序中的自定义健康检查?

我的 Program.cs 目前有 endpoints.MapCustomHealthChecks("ApplicationName", "ApplicationVersion");。它工作正常,除了我需要在每次更改版本时进行代码更新。然而,这两个参数都在我的 .csproj 文件中,所以我想知道是否可以使用它们。

var publisherName = Assembly.GetEntryAssembly().GetName().Name;
var publisherVersion = Assembly.GetEntryAssembly().GetName().Version.ToString();
endpoints.MapCustomHealthChecks(publisherName, publisherVersion);