1

I have a simple console app which needs to load its configuration from appsettings.json. I'm publishing from VS2019 using the "Produce single file" option.

The default behaviour is for publish to place appsettings.json inside the single file. That's no good to me because I want to be able to edit the configuration file in-place on the Linux server where it will be deployed.

It's possible to exclude appsettings.json from the bundled file by adding an option to its entry in the project file - <ExcludeFromSingleFile>true</ExcludeFromSingleFile> works great and causes VS2019 to publish the appsettings.json file alongside the binary.

However...

When I run the binary (from /opt/MyApp/MyApp), and log the location from which it's trying to load appsettings.json, I see:

Loading settings from /var/tmp/.net/MyApp/jq1u11uk.4ap/appsettings.json

So my edited /opt/MyApp/appsettings.json is being ignored.

Is there some intended way to keep appsettings.json editable when using this publish option?

(This question was also asked at How to handle Appsettings for .net core 3.1 self contained single file publish, but was never answered in a way that solves being able to edit the file in-place.)

jlmt
  • 1,947
  • 1
  • 13
  • 16
  • Why do you need to edit `appsettings.json`? You may change the settings values using environment variables – Pavel Anikhouski May 30 '20 at 18:49
  • Thanks - appreciated that there are other approaches, but in this case am looking to be able to edit a text file. – jlmt May 30 '20 at 19:21
  • This is also useful if you're mounting the appSettings dynamically using something like Vault by Hashicorp. – Raphael Apr 07 '21 at 20:07

1 Answers1

0

Turns out that this has been solved elsewhere - now working well after following this answer: https://stackoverflow.com/a/58307732/2847257

jlmt
  • 1,947
  • 1
  • 13
  • 16