Changing IHostingEnvironment.ApplicationName using ASPNETCORE_APPLICATIONNAME env variable
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
Currently it not possible to change IHostingEnvironment.ApplicationName property via environment variables.
Although the variable is correctly read in the WebHostBuilder class, it is overwritten in the UseStartup method.
https://github.com/aspnet/AspNetCore/blob/d24ec01224726fa85dc7683d0f70a94d9172bc94/src/Hosting/Hosting/src/WebHostBuilder.cs#L45
https://github.com/aspnet/AspNetCore/blob/d24ec01224726fa85dc7683d0f70a94d9172bc94/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs#L75
### Describe the solution you'd like
Maybe this fix in UseStartup method will solve the problem:
```cs
public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, Type startupType)
{
if (string.IsNullOrEmpty(hostBuilder.GetSetting(WebHostDefaults.ApplicationKey)))
{
var startupAssemblyName = startupType.GetTypeInfo().Assembly.GetName().Name;
hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName);
}
// ...
}
```
Contributor guide
Assessment
This issue has not been assessed yet.