If, like me, you’re running up against this problem while trying to automate your build process using msbuild from the command line. Specifically, the parameter you need to set is:
/p:AutoParameterizationWebConfigConnectionStrings=False
This is most likely what VS is doing on your behalf when you publish to the filesystem