How to persist from build programmatically?

戏子无情 提交于 2019-12-13 01:28:00

问题


I want to be able to load some information programmatically into Properties.Settings.Default before I publish it, but it doesn't persist. How do I overcome that?

I have (as a test):

private void button1_Click(object sender, EventArgs e)
{
    Properties.Settings.Default.Setting1 = "abc";
    Properties.Settings.Default.Save();
}

private void button2_Click(object sender, EventArgs e)
{
    Text = Properties.Settings.Default.Setting1;
}

I clicked on button1, then published (with clickonce) and then run the published application and clicked on button2. The Text was empty.

If don't publish the application, rather just close it and reopen it and click on button2 – I get "abc".


回答1:


See the following post http://www.codeproject.com/Articles/17659/How-To-Use-the-Settings-Class-in-C




回答2:


publishing won't click the button for you.

You need to detect the setting isn't initialised correctly (compare with an application setting perhaps) and then set and save it yourself.

Blank / doesn't exist / = somesettingToUpgrade

and a little routine to find a setting by name, set and save then you could put that in the button click handler as well as say FormLoad.




回答3:


It seems that the problem was that the scope was "user". But if the scope is "application" – it can't be changed programmatically.

So there seems not to be a way to do it. Persist from build programmatically, that is.



来源:https://stackoverflow.com/questions/10302772/how-to-persist-from-build-programmatically

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