I want to declare a custom DLL as "hosting startup assembly" in an ASP.NET Core 7.0 web application. This is explained here, but unfortunately I cannot implement it for WebApplication.
The sample code given there shows this for IHostBuilder, but I need a WebApplicationBuilder. Can this also be done for web applications with the new "minimal hosting model"?
I'm afraid this is not possible or is there a way to set the HostingStartupAssembliesKey in the new "minimal hosting model" of ASP.NET as of 6.0? As you can see here, the new WebApplicationOptions class doesn't offer any way to do this.
I want to explicitly specify the hosting-startup-assembly in the code, with an environment variable (ASPNETCORE_HOSTINGSTARTUPASSEMBLIES) everything already works.
This isn't supported by WebApplicationBuilder
, but, as an official workaround, you can just set the environment variable in code before creating the WebApplicationBuilder
:
Environment.SetEnvironmentVariable(
$"ASPNETCORE_{WebHostDefaults.HostingStartupAssembliesKey}",
"[ASSEMBLY_HERE]");
var builder = WebApplication.CreateBuilder(args);
Reference: Modify startup assemblies using the minimal hosting model.