3

To migrate an application I want to continue using the plain old settings that still come along with .Net5 (App.Config, Settings.settings and so on).
I need a simple built in solution without additional dependencies.

The proposed way seems to be appsettings.json or similar.
For that to use with WPF you need to add some additonal dependencies which bloat the project when publishing it as single exe (not self contained). It is over-the-top for simple applications.

I followed the steps here: Equivalent to UserSettings / ApplicationSettings in WPF dotnet core The accepted answer from Alexander works for a normal exe built.

These are the generated files
MyApp.dll
MyApp.dll.config
MyApp.exe

Modifying "MyApp.dll.config" with an editor directly reflects the changed data in the code.

MessageBox.Show(Settings.Default.SomeConfigValue);

The used config file can be displayed using

var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
MessageBox.Show(config.FilePath);

It displays
C:\Projekte\MyApp\MyApp\bin\Debug\net5.0-windows\MyApp.dll.config

Unfortunately this fails for single exe

These are the generated files (in publish folder)
MyApp.dll.config
MyApp.exe

Modifying "MyApp.dll.config" or "MyApp.exe.config" has no effect. The file does not seem to be used by the framework.
Above messagebox now shows
C:\Projekte\MyApp\Publish<Unknown>.config

How to get the built-in configuration system work with single exe?

TomB
  • 641
  • 5
  • 17
  • App.config is not the "built-in configuration system" on .NET Core where publishing of single-file executables is supported. Did you read [this](https://blog.magnusmontin.net/2019/09/22/single-file-exes-in-net-core/)? – mm8 Dec 22 '20 at 16:44
  • While app.config may be "the old way," it seems to work just fine with the sole exception of single file. Quite frustrating that this would be implemented just enough to keep one chasing a fix, especially since applicationsettings.json is a few extra steps anyway outside of aspnet core. – Chad Schouggins Feb 22 '21 at 03:16

0 Answers0