C#读取exe版本号
来源:互联网 发布:天池大数据科研平台 编辑:程序博客网 时间:2024/05/29 18:56
通常我们做软件自动更新,需要比较新文件与旧文件的版本号,如果新文件的版本号比旧文件高,就替换旧文件。(版本号一般是在Visual Studio的程序信息里定义)如果使用以下的方法:
using System.Reflection;
using System.IO;
...
Assembly currentAssembly = Assembly.LoadFile(currentAssemblyPath);
Assembly updatedAssembly = Assembly.LoadFile(updatedAssemblyPath);
AssemblyName currentAssemblyName = currentAssembly.GetName();
AssemblyName updatedAssemblyName = updatedAssembly.GetName();
// 比较版本号
if (updatedAssemblyName.Version.CompareTo(currentAssemblyName.Version) <= 0)
{
// 不需要更新
return;
}
// 更新
File.Copy(updatedAssemblyPath, currentAssemblyPath, true);
旧版本被加载了,下面的File.Copy就无法替换旧文件。
不用加载EXE就可以判断该EXE版本的方法如下:
using System.Reflection;
using System.IO;
...
AssemblyName currentAssemblyName = AssemblyName.GetAssemblyName(currentAssemblyPath);
AssemblyName updatedAssemblyName = AssemblyName.GetAssemblyName(updatedAssemblyPath);
// 比较版本
if (updatedAssemblyName.Version.CompareTo(currentAssemblyName.Version) <= 0)
{
// 不需要更新
return;
}
// 更新
File.Copy(updatedAssemblyPath, currentAssemblyPath, true);
- C#读取exe版本号
- C#读取exe版本号
- C#读取exe版本号
- c# winform获取当前路径exe程序的版本号
- 获取Exe版本号
- 获取exe的版本号
- 读取软件版本号
- 读取设备版本号
- ant 读取 svn版本号
- 数据库 版本号读取
- 修改exe图标,加入版本号
- 获取DLL或者EXE版本号
- windows获取.exe文件版本号
- C#读取excel后不能关闭excel.exe
- C#中读取exe文件的icon类
- C# 获取网关地址 读取配置文件 打开关闭exe
- c# 自动生成版本号
- c#获取程序版本号
- WinPE下安装XP后启动显示NTLDR is missing
- Eclipse快捷键大全(转载)
- Windows模拟linux(或者linux部分)环境
- 找回JPS命令
- 一道简单的google笔试题
- C#读取exe版本号
- 浅谈iOS MVC 学习基础
- 学一点破解的知识
- Hibernate HQL 语法 及相关的外键关联
- hibernate注解与xml
- 兄弟情义、团队
- 修改hosts复活Google
- VS2008与VC6.0的变化
- 深入解析android log的分析方法(2)