如何以编程方式获取C#中的当前产品版本?
我的代码:
VersionNumber = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
Run Code Online (Sandbox Code Playgroud)
我得到VersionNumber = 1.0.0.0,但当前版本是1.0.0.12.
小智 70
有三个版本:程序集,文件和产品.要获得产品版本:
using System.Reflection;
using System.Diagnostics;
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fileVersionInfo.ProductVersion;
Run Code Online (Sandbox Code Playgroud)
Niv*_*kia 26
我得到了我的问题的答案它只是提供System.Deployment.Application的引用,虽然它不会在Visual Studio的开发中工作,但它将在部署应用程序后工作.
//using System.Deployment.Application;
//using System.Reflection;
public string CurrentVersion
{
get
{
return ApplicationDeployment.IsNetworkDeployed
? ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString()
: Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
小智 18
System.Reflection.Assembly.GetEntryAssembly().GetName().Version
Run Code Online (Sandbox Code Playgroud)
获取产品版本(使用其指定AssemblyInformationalVersionAttribute
)的另一种方法是
private static string AssemblyProductVersion
{
get
{
object[] attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
return attributes.Length == 0 ?
"" :
((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
在 C# 中,您需要使用反射和诊断
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fileVersionInfo.ProductVersion;
Run Code Online (Sandbox Code Playgroud)
尝试这个:
var thisApp = Assembly.GetExecutingAssembly();
AssemblyName name = new AssemblyName(thisApp.FullName);
VersionNumber = "v. " + name.Version;
Run Code Online (Sandbox Code Playgroud)
此外,请参阅有关该属性的此 Microsoft DocAssemblyName.Version
。
归档时间: |
|
查看次数: |
80423 次 |
最近记录: |