Skip to content

Add UserSecrets also on Local environment #26539

@lkurzyniec

Description

@lkurzyniec

Currently CreateDefaultBuilder() adds UserSecrets only for Development env.
https://github.com/dotnet/aspnetcore/blob/master/src/DefaultBuilder/src/WebHost.cs

if (env.IsDevelopment())
{
    var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
    if (appAssembly != null)
    {
        config.AddUserSecrets(appAssembly, optional: true);
    }
}

Solution

I would like to have UserSecrets also for Local env.

if (env.IsDevelopment() || env.IsEnvironment("Local")) // or env.IsLocal() would be even better with a bit more changes
{
    var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
    if (appAssembly != null)
    {
        config.AddUserSecrets(appAssembly, optional: true);
    }
}

Additional context

Usually Development env is a first stage of deploying whole solution (like QA). But earlier we have Local development on local machine where we have own configuration of environment (ie docker, sql server, etc). This requires to have separate appsettings.Local.json file with local settings (ie urls, passwords, server names, queues etc). I don't want to commit my local secrets, so I'm using UserSecrets to keep them safe.

If you would like to I can create a PR for that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-hostingIncludes Hostingarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions