ClickOnce 获取客户端发布版本号
做项目时使用智能客户端开发,在客户端需要获取发布的版本号,记录下来,以备查看。
/// <summary>
/// 获取客户端发布版本号
/// </summary>
/// <returns>当前版本号</returns>
private static string GetVersiion()
{
var version = "";
if(ApplicationDeployment.IsNetworkDeployed)//是否已连接
{
ApplicationDeployment currDeployment = ApplicationDeployment.CurrentDeployment;
DateTime lastCheck = currDeployment.TimeOfLastUpdateCheck.ToLocalTime();
var lastDay = lastCheck.Date.ToShortDateString();
var lastTime = lastCheck.TimeOfDay.ToString();
var majorVersion = currDeployment.CurrentVersion.Major.ToString();//主版本
var minorVersion = currDeployment.CurrentVersion.Minor.ToString(); //次版本
var revisionVersion = currDeployment.CurrentVersion.Revision.ToString();//内部版本号
var blildVersion = currDeployment.CurrentVersion.Build.ToString();//修订号
version = majorVersion + "." + minorVersion + "." + blildVersion + "." + revisionVersion;
}
return version;
}
作者:chhuic
出处:http://chhuic.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。