//获取程序Properties文件夹下面的AssemblyInfo.cs文件, [assembly: AssemblyVersion("1.0.0.1")]
public string GetVersion()
{
System.Reflection.Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
System.Reflection.AssemblyName assemblyName = null;
foreach (System.Reflection.Assembly assembly in assemblies)
{
// 根据需要筛选程序集,例如通过程序集名称
if (assembly.FullName.StartsWith("Project.Web"))
{
assemblyName = assembly.GetName();
break;
}
}
string version = assemblyName.Version.ToString();
if (version.EndsWith(".0"))
{
version = version.Substring(0, version.Length - 2);
}
return version;
}