'web.config file reverting to previous after build?

I'm having a puzzling problem with my web.config file on Visual Studio 2015. I open the project, open the web.config file and update a connection string to point to a different database source. I save the change and then close the web.config file. If I open back up the web.config file, the updates that I made are still there. But after I do a build, if I open the web.config file my update has reverted to what was there previously. Any ideas why?



Solution 1:[1]

I had the same issue. Turns out there was a modification to the default setup in my .csproj file...

<Target Name="BeforeBuild">
    <TransformXml Source="Web.Template.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
</Target>

This generates the web.config file at Build time based on Web.debug.config, Web.release.config, etc.

As described in this article: http://www.kongsli.net/2012/01/13/enabling-web-transforms-when-debugging-asp-net-apps/

Solution 2:[2]

Not sure if this applies to your case, but there is an "applicationhost.config" file in the "\YourAppName\.vs\config" folder that should be off the root of your project. Make sure all the links there are pointing to the current solution.

This just happened to me because I made a copy of an existing project to a new location and modified it. I came back after successful builds suddenly and ALL my web.config settings reverted to the original copy. Every node in the "web.config" matched to a "T". I edited any references from the old location to the new and hopefully this will no longer be an issue. This file apparently is not included in the search as it didn't come up when I looked for the old path within my project. Make sure you do a search for the old path also, just to be sure that it is not going to be an issue.

enter image description here

Solution 3:[3]

Try removing folder "obj" in the project's directory then rebuild the project.

Folder location:
$(ProjectDir)obj

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike W
Solution 2 Danimal111
Solution 3 Darius