I added an App.config file to my C# project and it has a lot in there: appSettings, connectionStrings, entityFramework, system.net mailSettings, etc. etc.
When I build the project, the resulting <assemblyname>.exe.config file is a completely different file: Not a single thing in my source App.config is there! All that's in the file generated by the build are a few automatically generated assembly binding redirects.
The App.config file is added to the project by default with Build Action = None and Copy to Output Directory = Do not copy; I tried changing it to Copy if newer and Copy always — didn't change the resulting built file.
I took those automatically generated <assemblyBinding> from the *.exe.config file and manually added them to my source App.config, see if that would stop Visual Studio's build from overwriting my whole App.config — also made no difference.
Closed Visual Studio, deleted the .vs folder, tried again — same results.
Why would Visual Studio totally ignore my project's App.config file and generate it's own .exe.config that doesn't copy anything from the original??
Most importantly, how do I get VS to stop doing that?
Update - more info: The project that has the App.config is a Windows Service, on .NET Framework 4.8. I have tried deleting all obj/bin folders as well and when I build, the same thing happens every time.
Can you provide more details on the type of Project you are trying to build and also which version of .NET you are using?
Ensure you have the latest version of Visual Studio 2022 installed. You can also try deleting the contents in "bin" and "obj" directories and re-build the project. Additionally double-check that you do not have any unwanted configuration transformation extensions active.
Also check if there are any Pre/Post-Build events that would be interfering with the correct App.config being loaded.
Update: Investigating further, unfortunately this seems to be an issue that has been present for some time in Visual Studio which has not been addressed or properly resolved:
https://developercommunity.visualstudio.com/t/applicationexeconfig-being-overwritten-during-buil/610276
A post by Cailin Spain in that thread suggests the following :