-
Notifications
You must be signed in to change notification settings - Fork 2
/
AssemblyUtils.cs
53 lines (45 loc) · 1.68 KB
/
AssemblyUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.IO;
using System.Reflection;
internal static class AssemblyUtils {
/// <summary>
/// Copies the current assembly to the destination, if necessary.
/// </summary>
/// <param name="destination">Destination path. Includes filename.</param>
/// <returns>False if the copy was skipped</returns>
public static bool CopyTo(string destination) {
if (!Assembly.GetExecutingAssembly().Location.Equals(destination, StringComparison.OrdinalIgnoreCase)) {
if (!File.Exists(destination) || HasAssemblyChanged(destination)) {
File.Copy(Assembly.GetExecutingAssembly().Location, destination, true);
return true;
}
}
return false;
}
public static bool HasAssemblyChanged(string otherAssemblyPath) {
try {
byte[] existing = File.ReadAllBytes(otherAssemblyPath);
byte[] current = File.ReadAllBytes(Assembly.GetExecutingAssembly().Location);
if (existing.Length != current.Length) {
return true;
}
for (int i = 0; i < existing.Length; i++) {
if (existing[i] != current[i]) {
return true;
}
}
return false;
} catch {
return true;
}
}
public static Version GetVersion() {
return Assembly.GetExecutingAssembly().GetName().Version;
}
public static Version GetCLRVersion() {
return GetCLRVersion(typeof(AssemblyUtils));
}
public static Version GetCLRVersion(Type type) {
return new Version(Assembly.GetAssembly(type).ImageRuntimeVersion.TrimStart('v'));
}
}