@@ -67,10 +67,11 @@ private static int Wain(string[] args)
67
67
var debugMode = app . Option ( DebugFlagShort + " | " + DebugFlagLong , "Enables debug output." , CommandOptionType . NoValue ) ;
68
68
var verbosity = app . Option ( "--verbosity" , " Set the verbosity level of the command. Allowed values are t[trace], d[ebug], i[nfo], w[arning], e[rror], and c[ritical]." , CommandOptionType . SingleValue ) ;
69
69
var nocache = app . Option ( "--no-cache" , "Disable caching (Restore and Dll cache)" , CommandOptionType . NoValue ) ;
70
+ var isolatedLoadContext = app . Option ( "--isolated-load-context" , "Use isolated assembly load context" , CommandOptionType . NoValue ) ;
70
71
var infoOption = app . Option ( "--info" , "Displays environmental information" , CommandOptionType . NoValue ) ;
71
72
72
73
var argsBeforeDoubleHyphen = args . TakeWhile ( a => a != "--" ) . ToArray ( ) ;
73
- var argsAfterDoubleHyphen = args . SkipWhile ( a => a != "--" ) . Skip ( 1 ) . ToArray ( ) ;
74
+ var argsAfterDoubleHyphen = args . SkipWhile ( a => a != "--" ) . Skip ( 1 ) . ToArray ( ) ;
74
75
75
76
const string helpOptionTemplate = "-? | -h | --help" ;
76
77
app . HelpOption ( helpOptionTemplate ) ;
@@ -99,7 +100,7 @@ private static int Wain(string[] args)
99
100
}
100
101
101
102
var logFactory = CreateLogFactory ( verbosity . Value ( ) , debugMode . HasValue ( ) ) ;
102
- var options = new ExecuteCodeCommandOptions ( source , cwd . Value ( ) , app . RemainingArguments . Concat ( argsAfterDoubleHyphen ) . ToArray ( ) , configuration . ValueEquals ( "release" , StringComparison . OrdinalIgnoreCase ) ? OptimizationLevel . Release : OptimizationLevel . Debug , nocache . HasValue ( ) , packageSources . Values ? . ToArray ( ) ) ;
103
+ var options = new ExecuteCodeCommandOptions ( source , cwd . Value ( ) , app . RemainingArguments . Concat ( argsAfterDoubleHyphen ) . ToArray ( ) , configuration . ValueEquals ( "release" , StringComparison . OrdinalIgnoreCase ) ? OptimizationLevel . Release : OptimizationLevel . Debug , nocache . HasValue ( ) , packageSources . Values ? . ToArray ( ) ) ;
103
104
return await new ExecuteCodeCommand ( ScriptConsole . Default , logFactory ) . Execute < int > ( options ) ;
104
105
} ) ;
105
106
} ) ;
@@ -231,11 +232,15 @@ private static int Wain(string[] args)
231
232
return 0 ;
232
233
}
233
234
235
+ AssemblyLoadContext assemblyLoadContext = null ;
236
+ if ( isolatedLoadContext . HasValue ( ) )
237
+ assemblyLoadContext = new ScriptAssemblyLoadContext ( ) ;
238
+
234
239
if ( scriptFile . HasValue )
235
240
{
236
241
if ( interactive . HasValue ( ) )
237
242
{
238
- return await RunInteractiveWithSeed ( file . Value , logFactory , scriptArguments , packageSources . Values ? . ToArray ( ) ) ;
243
+ return await RunInteractiveWithSeed ( file . Value , logFactory , scriptArguments , packageSources . Values ? . ToArray ( ) , assemblyLoadContext ) ;
239
244
}
240
245
241
246
var fileCommandOptions = new ExecuteScriptCommandOptions
@@ -248,42 +253,40 @@ private static int Wain(string[] args)
248
253
nocache . HasValue ( )
249
254
)
250
255
{
251
- AssemblyLoadContext = CreateAssemblyLoadContext ( )
256
+ AssemblyLoadContext = assemblyLoadContext
252
257
} ;
253
258
254
259
var fileCommand = new ExecuteScriptCommand ( ScriptConsole . Default , logFactory ) ;
255
260
return await fileCommand . Run < int , CommandLineScriptGlobals > ( fileCommandOptions ) ;
256
- }
261
+ }
257
262
else
258
263
{
259
- await RunInteractive ( ! nocache . HasValue ( ) , logFactory , packageSources . Values ? . ToArray ( ) ) ;
264
+ await RunInteractive ( ! nocache . HasValue ( ) , logFactory , packageSources . Values ? . ToArray ( ) , assemblyLoadContext ) ;
260
265
}
261
266
return exitCode ;
262
267
} ) ;
263
268
264
269
return app . Execute ( argsBeforeDoubleHyphen ) ;
265
270
}
266
271
267
- private static async Task < int > RunInteractive ( bool useRestoreCache , LogFactory logFactory , string [ ] packageSources )
272
+ private static async Task < int > RunInteractive ( bool useRestoreCache , LogFactory logFactory , string [ ] packageSources , AssemblyLoadContext assemblyLoadContext )
268
273
{
269
274
var options = new ExecuteInteractiveCommandOptions ( null , Array . Empty < string > ( ) , packageSources )
270
275
{
271
- AssemblyLoadContext = CreateAssemblyLoadContext ( )
276
+ AssemblyLoadContext = assemblyLoadContext
272
277
} ;
273
278
await new ExecuteInteractiveCommand ( ScriptConsole . Default , logFactory ) . Execute ( options ) ;
274
279
return 0 ;
275
280
}
276
281
277
- private async static Task < int > RunInteractiveWithSeed ( string file , LogFactory logFactory , string [ ] arguments , string [ ] packageSources )
282
+ private async static Task < int > RunInteractiveWithSeed ( string file , LogFactory logFactory , string [ ] arguments , string [ ] packageSources , AssemblyLoadContext assemblyLoadContext )
278
283
{
279
284
var options = new ExecuteInteractiveCommandOptions ( new ScriptFile ( file ) , arguments , packageSources )
280
285
{
281
- AssemblyLoadContext = CreateAssemblyLoadContext ( )
286
+ AssemblyLoadContext = assemblyLoadContext
282
287
} ;
283
288
await new ExecuteInteractiveCommand ( ScriptConsole . Default , logFactory ) . Execute ( options ) ;
284
289
return 0 ;
285
290
}
286
-
287
- static AssemblyLoadContext CreateAssemblyLoadContext ( ) => new ScriptAssemblyLoadContext ( ) ;
288
291
}
289
292
}
0 commit comments