zu1b
zu1b

Reputation: 585

VS2022 Configure Azure keyvault not seeing local secrets.json

I want to build an new .net core console application using the Azure KeyVault. I use the connected services wizard and select azure keyvault. It recognizes the vault instance I have access to but then comes a config pages like so:

enter image description here

Save connection string shows none as the possible options. I have a local secrets.json configured for the local secrets. Why can I not select this as an option? How do I get the wizard to recognize something here?

Upvotes: 1

Views: 1000

Answers (1)

Kartik Bhiwapurkar
Kartik Bhiwapurkar

Reputation: 5167

• According to experts, there might be bug in Visual Studio 2022 due to which the ‘secrets.json’ file is not getting saved as this doesn’t happen in Visual Studio 2019. As due to this bug only, you may not be able to refer the ‘local secrets.json’ file during creation of a .Net core console application.

You can report this bug on Visual Studio Community to Microsoft Support in here: - https://visualstudio.microsoft.com/support/. In the meantime, you can refer to the below alternative solution to refer to your created ‘local secrets.json’ file through an environment variable. To override the AppSettings:ConnectionStrings setting on individual machines, each user needs to add a user secret with the same name. The easiest approach is to use the Manage user secrets option in Visual Studio for a project.

• This itself will create a new empty JSON file for the secrets and is stored in ‘C:\Users\<username>\AppData\Roaming\Microsoft\UserSecrets\<id>’ where matches your Windows user and is a randomly generated GUID. Also, since this file is located outside of your project directory, you will have to bind the ‘local secrets.json’ file to your project by adding a bit of markup to the ‘csproj’ file as below: -

  <PropertyGroup>
  <UserSecretsId>dda25df4-9a88-4a7e-8502-2134b74e4729</UserSecretsId>
  </PropertyGroup>

Finally, to override the ‘AppSettings:ConnectionString’ setting, add a similar structure to the secrets.json file as below and place it in the root of your project.

   {
     "AppSettings:ConnectionString": "http://localhost:9000?user=username&password=1234"

}

For more details regarding this, kindly refer to the community discussion below: -

the configuration file 'secrets.json' was not found and is not optional (.NET 6)

Upvotes: 2

Related Questions