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.
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
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.
Content
not None
. –
Spitz None
, Do Not Copy
. I changed it to Content
, Copy always
and I still have the issue described. After testing several settings I found that Build Action: Embedded Resource
is the only one that works. Will drop a test project on Github and add the link here. –
Trek Content
and Copy If Newer
. Anyway, I also can reproduce the issue you have found. One thing I'd like to add is that if there are any changes in Program.cs, the new settings will be picked up. –
Spitz 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.
appsettings.json
is not picked up by MSBuild right (unless I make another change to a code file)? The issue linked seem to be a different issue. –
Summersault Fixed on Visual Studio 17.7 release August 8, 2023:
https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes#17.7.0
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.
- Run cleanup.
- 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.
My workaround is:
- Open appsettings.json properties
- Change 'Copy to output directory' for some another value than you have
- Ctrl + S
- Return 'Copy to output directory' to the original value
- Ctrl + S
- Build and run.
Terrible solution tho...
© 2022 - 2024 — McMap. All rights reserved.