Changes to appsettings.json config files not picked up?

3.1k Views Asked by At

I recently noticed some strange behaviour in Visual Studio. If I edit my appsettings.json file then run in debug F5, the changed config is not picked up by the compiler.

5

There are 5 best solutions below

8
AndyS On

The reason appears to be due to a new feature, called Build Acceleration, introduced into Visual Studio v17.5 (Feb 2023)

Release notes: https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes
Build Acceleration: https://github.com/dotnet/project-system/blob/main/docs/build-acceleration.md

enter image description here

Build Acceleration will only recompile projects that have code changes. It won't pick up changes to settings files that have Build Action: None, which is the default value. Previously VS would run MSBuild, which would update changed files and run a build. Now VS handles the file changes itself, and only calls MSBuild when needed. The result is that edits on the settings file don't get picked up, unless you also edit a code file, or explicitly build (Ctrl+B or Ctrl+Shift+B) before running debug.

Test project on GitHub

EDIT: After a bit of testing, Build Action: Embedded Resource seems to work best. I tried Content but still got the same issue and Resource threw a runtime error. Grab the test project above if you want to experiment.

2
Drew Noakes On

EDIT This issue was fixed in VS 17.7 via this PR.


This is a known bug in VS and is being tracked by:

https://developercommunity.visualstudio.com/t/Copy-if-newer---Issue-when-only-non-sour/10308822

Please vote on the ticket if its impacting you.

A workaround is to hit Build before pressing F5. The problem only occurs when launching the debugger in this way, as the build is skipped.

0
Shreya Sakshi On

Faced the same issue there is one solution to it but yes, that is not convenient for all but until they provide a fix, this can be done.

  1. Run cleanup.
  2. Run rebuild solution.

Then, when you run the code it will start picking up changes in appsettings.json file. Still searching for better solution will update if I find one.

0
Reznik D On

My workaround is:

  1. Open appsettings.json properties
  2. Change 'Copy to output directory' for some another value than you have
  3. Ctrl + S
  4. Return 'Copy to output directory' to the original value
  5. Ctrl + S
  6. Build and run.

Terrible solution tho...

0
DevRacker On

Fixed on Visual Studio 17.7 release August 8, 2023:

https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes#17.7.0