I'm trying to write a custom healthcheck and put it into Nuget for reuse. For the app (.netcore 3.1) to use this healthcheck it needs to call
appBuilder.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/health", new HealthCheckOptions
{
ResultStatusCodes =
{
[HealthStatus.Healthy] = StatusCodes.Status200OK,
[HealthStatus.Degraded] = StatusCodes.Status200OK,
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable
},
AllowCachingResponses = false,
ResponseWriter = HealthCheckResponseWriter.WriteResponse
});
});
in addition to other calls in ConfigureServices. I'd like to move this part of the code into my nuget, but encountered not really understanding what Nugets do I need to use to be able to use both IApplicationBuilder and UseEndpoints extensions method in my class library? As it turned out I can do this without any problems from other app with .NET.Sdk.Web but not from the class library. It looks like that all the dependencies needed for it are implicitly added in the web sdk, but how can I figure out what should I add to the class library for this to work?
I have solved this problem.
With the release of .NET Core 3.0, many ASP.NET Core assemblies are no longer published to NuGet as packages. Instead, the assemblies are included in the Microsoft.AspNetCore.App shared framework, which is installed with the .NET Core SDK and runtime installers. For a list of packages no longer being published, see Remove obsolete package references.
As of .NET Core 3.0, projects using the Microsoft.NET.Sdk.Web MSBuild SDK implicitly reference the shared framework. Projects using the Microsoft.NET.Sdk or Microsoft.NET.Sdk.Razor SDK must reference ASP.NET Core to use ASP.NET Core APIs in the shared framework.
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-3.1&tabs=visual-studio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With