默认为自动更新,不过我认为手动更新更加的合理化一些.
想手动更新,只要在UPDATE中关闭"The application should check for updates"选项就可以了.
所以专门贴出手工更新的代码.这个代码是elearning视频上的,我把它记了下来,和大家分享一下.
1
if (ApplicationDeployment.IsNetworkDeployed == true)
2
{
3
ApplicationDeployment thisDeployment = ApplicationDeployment.CurrentDeployment;
4
this.Text = "正在检测更新
";
5
if (thisDeployment.CheckForUpdate() == true)
6
{
7
if (MessageBox.Show("检测到有新的版本可以进行更新,现在需要更新吗?", "选择是否要进行更新", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
8
{
9
this.Text = "正在更新中
";
10
thisDeployment.Update();
11
MessageBox.Show("更新完毕,将要重启程序!");
12
Application.Restart();
13
}
14
else
15
{
16
this.Text = Application.ProductName + " " + Application.ProductVersion;
17
}
18
}
19
else
20
{
21
MessageBox.Show("并没有新的版本进行更新!");
22
}
23
}
24
else
25
MessageBox.Show("这不是网络发布的程序");
if (ApplicationDeployment.IsNetworkDeployed == true)2
{3
ApplicationDeployment thisDeployment = ApplicationDeployment.CurrentDeployment;4
this.Text = "正在检测更新
";5
if (thisDeployment.CheckForUpdate() == true)6
{7
if (MessageBox.Show("检测到有新的版本可以进行更新,现在需要更新吗?", "选择是否要进行更新", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)8
{9
this.Text = "正在更新中
";10
thisDeployment.Update();11
MessageBox.Show("更新完毕,将要重启程序!");12
Application.Restart();13
}14
else15
{16
this.Text = Application.ProductName + " " + Application.ProductVersion;17
}18
}19
else20
{ 21
MessageBox.Show("并没有新的版本进行更新!"); 22
}23
}24
else25
MessageBox.Show("这不是网络发布的程序");ClickOnce确实很方便,让WINFROM很方便的部署和更新.不过通过我的实际使用,发现还是有些不稳定,发布时容易出错,关了VS再开又可以编译了,然而版本却自动降了一级,希望VS SP1能修正这些错误,呵...
浙公网安备 33010602011771号