我有一个我编写的程序,并正在尝试为其创建一个关于框。我最近将程序的产品版本更新为 1.00.0003,我希望这反映在 about 窗口中。
aboutBox 的默认设置显示值 1.0.0.0,这是程序集版本,而不是产品版本。从那以后,我一直在互联网上寻找如何获得要显示的产品版本。我已经尝试了所有这些:
{
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fileVersionInfo.ProductVersion;
Debug.WriteLine(version);
Debug.WriteLine(assembly.GetName().Version);
string v = VersionNumber;
Debug.WriteLine(v);
Debug.WriteLine( fileVersionInfo.FileVersion);
Debug.WriteLine(Application.ProductVersion);
Debug.WriteLine(AssemblyProductVersion);
Assembly assembly2 = Assembly.GetEntryAssembly();
FileVersionInfo fileVersionInfo2 = FileVersionInfo.GetVersionInfo(assembly.Location);
string version2 = fileVersionInfo2.ProductVersion;
Debug.WriteLine(version2);
Debug.WriteLine(assembly2.GetName().Version);
return version;
}
private string _ourVersion = "Version: v";
private string VersionNumber
{
get
{
System.Reflection.Assembly _assemblyInfo =
System.Reflection.Assembly.GetExecutingAssembly();
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
_ourVersion += ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
else
{
if (_assemblyInfo != null)
_ourVersion += _assemblyInfo.GetName().Version.ToString();
}
return _ourVersion;
}
}
private static string AssemblyProductVersion
{
get
{
object[] attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
return attributes.Length == 0 ?
"" :
((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
}
}
这些中的每一个都返回 1.0.0.0(是的,我确实在控制台中查找了它们的输出,而不是实际显示的内容),而不是像我需要的那样返回 1.00.0003。产品版本在 InstallShield 设置的常规信息选项卡中设置。安装后,转到“程序和功能”会显示 1.00.0003 的产品版本,所以我无法弄清楚为什么以编程方式检索该值如此困难。有任何想法吗?