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;
        }

你可能感兴趣的:(click)