aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Question: Is C# project with multiple secrets.json files (i.e. UserSecretId values) supported?

Open markm77 opened this issue 2 years ago • 2 comments

Hi there,

I have a C# solution with both an ASP.NET Core application project and a test project. I want the test project to use the same secrets.json file as the web-app project but also in addition a separate, second secrets.json file (for Git change control and other reasons) with test-specific configuration. (Neither secrets.json file contains configuration suitable for the open-source repo containing the solution, hence the use of the ASP.NET Core secrets manager.)

Is is possible to for me to specify two UserSecretId values in the same project (.csproj) file to allow use of two secrets.json files and is this a supported scenario?

BR, Mark

markm77 avatar Dec 19 '23 18:12 markm77

I believe to do this you need to explicitly configure secrets in code by specifying the additional name(s) in your tests' code: https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.usersecretsconfigurationextensions.addusersecrets

martincostello avatar Dec 19 '23 18:12 martincostello

Thanks Martin, appreciate your response!

It would be really great if additional code were not required and that multiple secrets.json files were supported out of the box by means of multiple UserSecretsId values.

This would trickle through to IDE support like (using Visual Studio as an example):

  1. automatic Windows <-> WSL2 secrets synchronisation that occurs for WSL debugging in Visual Studio synchronising all required secrets.json files
  2. the new secrets import feature in the Visual Studio HTTP client (https://devblogs.microsoft.com/visualstudio/safely-use-secrets-in-http-requests-in-visual-studio-2022/#using-secrets-from-asp-net-core-user-secrets) importing from all project-specified secrets.json files.

It would be great if someone from Microsoft could clarify intentions here so I can raise a feature request if required.

markm77 avatar Dec 19 '23 19:12 markm77