Force regeneration of Settings.settings file after change in app.config

岁酱吖の 提交于 2019-12-02 10:09:37

问题


I have an automated build process that sets up the application for a specified mode (e.g. Dev, uat, live). Depending on this mode I want to update Connection Strings to the relevant one.

However, in my Data Access Layer there is an app.config file which stores the connection string and this is used to feed the Settings.Settings file. In my builder I update the app.config's xml with the new Connection String and then the solution is built, however the Settings.setting file doesn't get regenerated with the updated app.config connection string and so the app doesn't connect to the correct DB.

Is it possible to do this or am I going about it the wrong way through a misunderstanding of how these config/settings files work?

Thanks Stuart


回答1:


Yeah, you're doing it backwards. The IDE generates the .config file contents from the settings you define in the Settings designer. That doesn't work the other way around. If getting the connection string valid straight from the build is important then set the default in the Settings designer. Or don't store it in a setting.




回答2:


There is a way to override the settings.settings :

Project.Properties.Settings.Default["ConnectionString"] = ConfigurationManager.ConnectionStrings["Project.Properties.Settings.ConnectionString"].ConnectionString;


来源:https://stackoverflow.com/questions/3768277/force-regeneration-of-settings-settings-file-after-change-in-app-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!