0

We currently use .Net Framework 4.8 but are upgrading Windows console apps to .Net 6.0. In 4.8, we would use Microsoft.Configuration.ConfigurationBuilders.UserSecrets to help manage keys in our app.config that we wanted to keep secret(production level keys mainly).

Our app.config would look like the following:

<configSections>
  <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxx" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
  <builders>
    <add name="Secrets" userSecretsId="production" type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=1.0.0.0, Culture=neutral" />
  </builders>
</configBuilders>
<appSettings configBuilders="Secrets">
  <add key="Sample" value="SECRET"
</appSettings> 

Our Production secrets.xml:

<root>
  <secrets ver="1.0">
    <secret name="Sample" value="production" />
  </secrets>
</root>

Anytime we would reference the key Sample, it would look at the key in app.config notice that the value was SECRET. Then it would go to AppData\Microsoft\UserSecrets\{userSecretId}\secrets.xml to replace SECRET with the value in secrets.xml

Is there a similar way to do this in .Net 6.0? I know the config files are changing to JSON but I would like to support this pattern while I upgrade. I also know that Microsoft.Configuration.ConfigurationBuilders.UserSecrets hasn't been released in a couple of years.

I appreciate any help.

0 Answers0