-
-
Notifications
You must be signed in to change notification settings - Fork 166
/
AssemblyLoader.cs
48 lines (42 loc) · 1.3 KB
/
AssemblyLoader.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
#if NETFRAMEWORK
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class ModuleInitializerAttribute : Attribute { }
}
namespace Nerdbank.GitVersioning.Tasks
{
internal static class AssemblyLoader
{
[ModuleInitializer]
internal static void LoaderInitializer()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
try
{
var required = new AssemblyName(args.Name);
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), required.Name + ".dll");
if (File.Exists(path))
{
AssemblyName actual = AssemblyName.GetAssemblyName(path);
if (actual.Version >= required.Version)
{
return Assembly.LoadFile(path);
}
}
}
catch
{
}
return null;
}
}
}
#endif