C# Winform如何自动获取版本号
方案一
缺点是不适配,clickones发布的版本
public static string GetVersion()
{
try
{
return System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
}
catch
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
方案二
try
{
string version = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
}
catch (Exception)
{
}
优点:自动获取,clickonces发布的版本
缺点:仅在安装后生效,debug期间会报错,需忽略此异常