Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit282963a

Browse files
authored
Merge pull request#631 from hrumhurum/gp-feature-a
Ability to isolate script execution with AssemblyLoadContext
2 parentsb0aadfa +353609e commit282963a

19 files changed

+414
-57
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,4 @@ project.json
265265
/build/dotnet-script
266266
/dotnet-script
267267
/.vscode
268+
/src/Dotnet.Script/Properties/launchSettings.json

‎src/Dotnet.Script.Core/Commands/ExecuteCodeCommand.cs‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ public async Task<TReturn> Execute<TReturn>(ExecuteCodeCommandOptions options)
2222
{
2323
varsourceText=SourceText.From(options.Code);
2424
varcontext=newScriptContext(sourceText,options.WorkingDirectory??Directory.GetCurrentDirectory(),options.Arguments,null,options.OptimizationLevel,ScriptMode.Eval,options.PackageSources);
25-
varcompiler=GetScriptCompiler(!options.NoCache,_logFactory);
26-
varrunner=newScriptRunner(compiler,_logFactory,_scriptConsole);
25+
varcompiler=newScriptCompiler(_logFactory,!options.NoCache)
26+
{
27+
#ifNETCOREAPP
28+
AssemblyLoadContext=options.AssemblyLoadContext
29+
#endif
30+
};
31+
varrunner=newScriptRunner(compiler,_logFactory,_scriptConsole)
32+
{
33+
#ifNETCOREAPP
34+
AssemblyLoadContext=options.AssemblyLoadContext
35+
#endif
36+
};
2737
returnawaitrunner.Execute<TReturn>(context);
2838
}
29-
30-
privatestaticScriptCompilerGetScriptCompiler(booluseRestoreCache,LogFactorylogFactory)
31-
{
32-
varcompiler=newScriptCompiler(logFactory,useRestoreCache);
33-
returncompiler;
34-
}
3539
}
3640
}

‎src/Dotnet.Script.Core/Commands/ExecuteCodeCommandOptions.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
usingMicrosoft.CodeAnalysis;
2+
#ifNETCOREAPP
3+
usingSystem.Runtime.Loader;
4+
#endif
25

36
namespaceDotnet.Script.Core.Commands
47
{
@@ -20,5 +23,14 @@ public ExecuteCodeCommandOptions(string code, string workingDirectory, string[]
2023
publicOptimizationLevelOptimizationLevel{get;}
2124
publicboolNoCache{get;}
2225
publicstring[]PackageSources{get;}
26+
27+
#ifNETCOREAPP
28+
#nullable enable
29+
/// <summary>
30+
/// Gets or sets a custom assembly load context to use for script execution.
31+
/// </summary>
32+
publicAssemblyLoadContext?AssemblyLoadContext{get;init;}
33+
#nullable restore
34+
#endif
2335
}
2436
}

‎src/Dotnet.Script.Core/Commands/ExecuteInteractiveCommand.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public ExecuteInteractiveCommand(ScriptConsole scriptConsole, LogFactory logFact
1818

1919
publicasyncTask<int>Execute(ExecuteInteractiveCommandOptionsoptions)
2020
{
21-
varcompiler=newScriptCompiler(_logFactory,useRestoreCache:false);
21+
varcompiler=newScriptCompiler(_logFactory,useRestoreCache:false)
22+
{
23+
#ifNETCOREAPP
24+
AssemblyLoadContext=options.AssemblyLoadContext
25+
#endif
26+
};
2227
varrunner=newInteractiveRunner(compiler,_logFactory,_scriptConsole,options.PackageSources);
2328

2429
if(options.ScriptFile==null)
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
usingMicrosoft.CodeAnalysis;
1+
#ifNETCOREAPP
2+
usingSystem.Runtime.Loader;
3+
#endif
24

35
namespaceDotnet.Script.Core.Commands
46
{
57
publicclassExecuteInteractiveCommandOptions
68
{
7-
publicExecuteInteractiveCommandOptions(ScriptFilescriptFile,string[]arguments,string[]packageSources)
9+
publicExecuteInteractiveCommandOptions(ScriptFilescriptFile,string[]arguments,string[]packageSources)
810
{
911
ScriptFile=scriptFile;
1012
Arguments=arguments;
@@ -14,5 +16,14 @@ public ExecuteInteractiveCommandOptions(ScriptFile scriptFile, string[] argument
1416
publicScriptFileScriptFile{get;}
1517
publicstring[]Arguments{get;}
1618
publicstring[]PackageSources{get;}
19+
20+
#ifNETCOREAPP
21+
#nullable enable
22+
/// <summary>
23+
/// Gets or sets a custom assembly load context to use for script execution.
24+
/// </summary>
25+
publicAssemblyLoadContext?AssemblyLoadContext{get;init;}
26+
#nullable restore
27+
#endif
1728
}
1829
}

‎src/Dotnet.Script.Core/Commands/ExecuteLibraryCommand.cs‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,20 @@ public async Task<TReturn> Execute<TReturn>(ExecuteLibraryCommandOptions options
2525
}
2626

2727
varabsoluteFilePath=options.LibraryPath.GetRootedPath();
28-
varcompiler=GetScriptCompiler(!options.NoCache,_logFactory);
29-
varrunner=newScriptRunner(compiler,_logFactory,_scriptConsole);
28+
varcompiler=newScriptCompiler(_logFactory,!options.NoCache)
29+
{
30+
#ifNETCOREAPP
31+
AssemblyLoadContext=options.AssemblyLoadContext
32+
#endif
33+
};
34+
varrunner=newScriptRunner(compiler,_logFactory,_scriptConsole)
35+
{
36+
#ifNETCOREAPP
37+
AssemblyLoadContext=options.AssemblyLoadContext
38+
#endif
39+
};
3040
varresult=awaitrunner.Execute<TReturn>(absoluteFilePath,options.Arguments);
3141
returnresult;
3242
}
33-
34-
privatestaticScriptCompilerGetScriptCompiler(booluseRestoreCache,LogFactorylogFactory)
35-
{
36-
varcompiler=newScriptCompiler(logFactory,useRestoreCache);
37-
returncompiler;
38-
}
3943
}
4044
}

‎src/Dotnet.Script.Core/Commands/ExecuteLibraryCommandOptions.cs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#ifNETCOREAPP
2+
usingSystem.Runtime.Loader;
3+
#endif
4+
15
namespaceDotnet.Script.Core.Commands
26
{
37
publicclassExecuteLibraryCommandOptions
@@ -12,5 +16,14 @@ public ExecuteLibraryCommandOptions(string libraryPath, string[] arguments, bool
1216
publicstringLibraryPath{get;}
1317
publicstring[]Arguments{get;}
1418
publicboolNoCache{get;}
19+
20+
#ifNETCOREAPP
21+
#nullable enable
22+
/// <summary>
23+
/// Gets or sets a custom assembly load context to use for script execution.
24+
/// </summary>
25+
publicAssemblyLoadContext?AssemblyLoadContext{get;init;}
26+
#nullable restore
27+
#endif
1528
}
1629
}

‎src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ public async Task<TReturn> Run<TReturn, THost>(ExecuteScriptCommandOptions optio
3232
}
3333

3434
varpathToLibrary=GetLibrary(options);
35-
returnawaitExecuteLibrary<TReturn>(pathToLibrary,options.Arguments,options.NoCache);
35+
36+
varlibraryOptions=newExecuteLibraryCommandOptions(pathToLibrary,options.Arguments,options.NoCache)
37+
{
38+
#ifNETCOREAPP
39+
AssemblyLoadContext=options.AssemblyLoadContext
40+
#endif
41+
};
42+
returnawaitnewExecuteLibraryCommand(_scriptConsole,_logFactory).Execute<TReturn>(libraryOptions);
3643
}
3744

3845
privateasyncTask<TReturn>DownloadAndRunCode<TReturn>(ExecuteScriptCommandOptionsexecuteOptions)
@@ -57,7 +64,12 @@ private string GetLibrary(ExecuteScriptCommandOptions executeOptions)
5764
returnpathToLibrary;
5865
}
5966

60-
varoptions=newPublishCommandOptions(executeOptions.File,executionCacheFolder,"script",PublishType.Library,executeOptions.OptimizationLevel,executeOptions.PackageSources,null,executeOptions.NoCache);
67+
varoptions=newPublishCommandOptions(executeOptions.File,executionCacheFolder,"script",PublishType.Library,executeOptions.OptimizationLevel,executeOptions.PackageSources,null,executeOptions.NoCache)
68+
{
69+
#ifNETCOREAPP
70+
AssemblyLoadContext=executeOptions.AssemblyLoadContext
71+
#endif
72+
};
6173
newPublishCommand(_scriptConsole,_logFactory).Execute(options);
6274
if(hash!=null)
6375
{
@@ -124,11 +136,5 @@ public bool TryGetHash(string cacheFolder, out string hash)
124136
hash=File.ReadAllText(pathToHashFile);
125137
returntrue;
126138
}
127-
128-
privateasyncTask<TReturn>ExecuteLibrary<TReturn>(stringpathToLibrary,string[]arguments,boolnoCache)
129-
{
130-
varoptions=newExecuteLibraryCommandOptions(pathToLibrary,arguments,noCache);
131-
returnawaitnewExecuteLibraryCommand(_scriptConsole,_logFactory).Execute<TReturn>(options);
132-
}
133139
}
134140
}

‎src/Dotnet.Script.Core/Commands/ExecuteScriptCommandOptions.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
usingMicrosoft.CodeAnalysis;
2+
#ifNETCOREAPP
3+
usingSystem.Runtime.Loader;
4+
#endif
25

36
namespaceDotnet.Script.Core.Commands
47
{
@@ -20,5 +23,14 @@ public ExecuteScriptCommandOptions(ScriptFile file, string[] arguments, Optimiza
2023
publicstring[]PackageSources{get;}
2124
publicboolIsInteractive{get;}
2225
publicboolNoCache{get;}
26+
27+
#ifNETCOREAPP
28+
#nullable enable
29+
/// <summary>
30+
/// Gets or sets a custom assembly load context to use for script execution.
31+
/// </summary>
32+
publicAssemblyLoadContext?AssemblyLoadContext{get;init;}
33+
#nullable restore
34+
#endif
2335
}
2436
}

‎src/Dotnet.Script.Core/Commands/PublishCommand.cs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ public void Execute(PublishCommandOptions options)
2828
(options.PublishType==PublishType.Library?Path.Combine(Path.GetDirectoryName(absoluteFilePath),"publish"):Path.Combine(Path.GetDirectoryName(absoluteFilePath),"publish",options.RuntimeIdentifier));
2929

3030
varabsolutePublishDirectory=publishDirectory.GetRootedPath();
31-
varcompiler=GetScriptCompiler(!options.NoCache,_logFactory);
31+
varcompiler=newScriptCompiler(_logFactory,!options.NoCache)
32+
{
33+
#ifNETCOREAPP
34+
AssemblyLoadContext=options.AssemblyLoadContext
35+
#endif
36+
};
3237
varscriptEmitter=newScriptEmitter(_scriptConsole,compiler);
3338
varpublisher=newScriptPublisher(_logFactory,scriptEmitter);
3439
varcode=absoluteFilePath.ToSourceText();
@@ -43,12 +48,5 @@ public void Execute(PublishCommandOptions options)
4348
publisher.CreateExecutable<int,CommandLineScriptGlobals>(context,_logFactory,options.RuntimeIdentifier,options.LibraryName);
4449
}
4550
}
46-
47-
privatestaticScriptCompilerGetScriptCompiler(booluseRestoreCache,LogFactorylogFactory)
48-
{
49-
50-
varcompiler=newScriptCompiler(logFactory,useRestoreCache);
51-
returncompiler;
52-
}
5351
}
5452
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp