我正在粘貼一個方法,我用它來查找程序的版本(如果它是從桌面啓動的)以及從ClickOnce啓動的更新版本。
private string GetTheVersion()
{
string version = string.Empty;
Version currentVersion;
Version updateVersion;
StringBuilder sb = new StringBuilder();
if (ApplicationDeployment.IsNetworkDeployed)
{
currentVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
updateVersion = ApplicationDeployment.CurrentDeployment.UpdatedVersion;
sb.AppendLine(string.Format("Current Version: {0}.{1}.{2}.{3}", currentVersion.Major.ToString(), currentVersion.Minor.ToString(), currentVersion.MajorRevision.ToString(), currentVersion.MinorRevision.ToString()));
sb.AppendLine(string.Format("Updated Version: {0}.{1}.{2}.{3}", updateVersion.Major.ToString(), updateVersion.Minor.ToString(), updateVersion.MajorRevision.ToString(), updateVersion.MinorRevision.ToString()));
version = sb.ToString();
}
else
{
currentVersion = Assembly.GetCallingAssembly().GetName().Version;
version = string.Format("Current Version: {0}.{1}.{2}.{3}", currentVersion.Major.ToString(), currentVersion.Minor.ToString(), currentVersion.MajorRevision.ToString(), currentVersion.MinorRevision.ToString());
}
return version;
}
有更多的有比你需要的,當然,但你可以使用ApplicationDeployment.CurrentDeployment類的方法,以確定是否要進行更新。您可以將現有應用的最低版本傳遞到命令行參數或url querystring變量中,具體取決於您的部署方式。
Joey