https://social.microsoft.com/Forums/es-ES/26786b8d-0155-4261-9672-11b786d8c1d6/clickonceandsetup
/// <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;
}
//获取版本号
try
{
var q = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion;
if (q != null)
{
string version = q.Major.ToString() + "." + q.Minor.ToString() + "." + q.Build.ToString() + "." + q.Revision.ToString();
}
}
catch
{
}