GFlisch / Arc4u.Guidance.Doc

Other
5 stars 1 forks source link

(Guidance 2022.2.1.14) appsettings.json in WPF is an embedded resource, forcing a rebuild for each environment #250

Open vvdb-architecture opened 1 month ago

vvdb-architecture commented 1 month ago

When generating a WPF application, the appsettings.json is set up to be read as an embedded resource:

  <ItemGroup>
    <EmbeddedResource Include="appsettings.json" />
  </ItemGroup>
        _configuration = ConfigurationHelper.GetConfigurationFromResourceStream("SolutionName.Wpf, EG.SolutionName.Wpf.appsettings.json");

The problem with this, is that you can't have a release pipeline for a specific environment, since the only way to include an embedded resource is to recompile the application with it. It's not sufficient to just overwrite the existing appsettings.json with the required appsettings.[environment].json, since this won't "embed" the file in the executable (and the file doesn't exist anyway).

It would be better to allow appsettings.json to exist as an ordinary file next to the application (like in back-ends, Blazor and Migration tools) and to read it with:

 _configuration = ConfigurationHelper.GetConfigurationFromFile("appsettings.json");

This way, the release pipeline can just overwrite the file with the one from the correct deployment environment.