File tree Expand file tree Collapse file tree 3 files changed +6
-55
lines changed
Expand file tree Collapse file tree 3 files changed +6
-55
lines changed Original file line number Diff line number Diff line change @@ -17,44 +17,5 @@ public static string GetCodebase(this string path)
1717 path = path . Replace ( '\\ ' , '/' ) ;
1818 return $ "file:///{ path } ";
1919 }
20-
21- internal static Assembly ReflectionOnlyLoadAssembly ( string path )
22- {
23- if ( File . Exists ( path ) )
24- {
25- var assemblyName = AssemblyName . GetAssemblyName ( path ) ;
26- var assemblies = AppDomain . CurrentDomain . ReflectionOnlyGetAssemblies ( ) ;
27- var existing = assemblies . FirstOrDefault ( assembly => assembly . FullName == assemblyName . FullName ) ;
28- if ( existing != null )
29- {
30- return existing ;
31- }
32-
33- var content = File . ReadAllBytes ( path ) ;
34- return Assembly . ReflectionOnlyLoad ( content ) ;
35- }
36-
37- return null ;
38- }
39-
40- internal static Assembly ReflectionOnlyAssemblyResolve ( ResolveEventArgs args , string baseDir )
41- {
42- Console . WriteLine ( $ "Assembly: { args ? . Name } by { args ? . RequestingAssembly ? . GetName ( ) } ") ;
43-
44- var name = new AssemblyName ( args . Name ) ;
45- var path = Path . Combine ( baseDir , name . Name + ".dll" ) ;
46- Assembly assembly = null ;
47- if ( File . Exists ( path ) )
48- {
49- assembly = ReflectionOnlyLoadAssembly ( path ) ;
50- }
51- else
52- {
53- // Log.LogWarning($"Loading assembly by name '{args.Name}'.");
54- assembly = Assembly . ReflectionOnlyLoad ( args . Name ) ;
55- }
56-
57- return assembly ;
58- }
5920 }
6021}
Original file line number Diff line number Diff line change 11using System ;
22using System . IO ;
3+ using System . Reflection ;
34using Microsoft . Build . Framework ;
45using Microsoft . Build . Utilities ;
56
67namespace NetOfficeFw . Build
78{
8- public class CleanAddin : Task
9+ public class CleanAddin : AppDomainIsolatedTask
910 {
1011 [ Required ]
1112 public ITaskItem AssemblyPath { get ; set ; }
@@ -19,9 +20,7 @@ public override bool Execute()
1920 var assemblyPath = this . AssemblyPath . ItemSpec ;
2021 var assemblyDir = Path . GetDirectoryName ( assemblyPath ) ;
2122
22- AppDomain . CurrentDomain . ReflectionOnlyAssemblyResolve += ( sender , args ) => AssemblyEx . ReflectionOnlyAssemblyResolve ( args , assemblyDir ) ;
23-
24- var assembly = AssemblyEx . ReflectionOnlyLoadAssembly ( assemblyPath ) ;
23+ var assembly = Assembly . UnsafeLoadFrom ( assemblyPath ) ;
2524 var publicTypes = assembly . GetExportedTypes ( ) ;
2625
2726 foreach ( var publicType in publicTypes )
Original file line number Diff line number Diff line change 55using System . Reflection ;
66using System . Security . Policy ;
77using Microsoft . Build . Framework ;
8+ using Microsoft . Build . Tasks ;
89using Microsoft . Build . Utilities ;
910
1011namespace NetOfficeFw . Build
1112{
12- public class RegisterAddin : Task
13+ public class RegisterAddin : AppDomainIsolatedTask
1314 {
1415 [ Required ]
1516 public ITaskItem AssemblyPath { get ; set ; }
@@ -24,15 +25,12 @@ public class RegisterAddin : Task
2425
2526 public override bool Execute ( )
2627 {
27- AppDomain domain = null ;
2828 try
2929 {
3030 var assemblyPath = this . AssemblyPath . ItemSpec ;
3131 var assemblyDir = Path . GetDirectoryName ( assemblyPath ) ;
3232
33- AppDomain . CurrentDomain . ReflectionOnlyAssemblyResolve += ( sender , args ) => AssemblyEx . ReflectionOnlyAssemblyResolve ( args , assemblyDir ) ;
34-
35- var assembly = AssemblyEx . ReflectionOnlyLoadAssembly ( assemblyPath ) ;
33+ var assembly = Assembly . UnsafeLoadFrom ( assemblyPath ) ;
3634 var assemblyName = assembly . GetName ( ) ;
3735 var assemblyCodebase = assemblyPath . GetCodebase ( ) ;
3836 var publicTypes = assembly . GetExportedTypes ( ) ;
@@ -115,13 +113,6 @@ public override bool Execute()
115113 Log . LogErrorFromException ( ex ) ;
116114 return false ;
117115 }
118- finally
119- {
120- if ( domain != null )
121- {
122- AppDomain . Unload ( domain ) ;
123- }
124- }
125116
126117 return true ;
127118 }
You can’t perform that action at this time.
0 commit comments