fix(scriptanalysis): warn on scripts blocking on a Task (.Result/.Wait()/GetAwaiter().GetResult()) (review 2026-10-21 01/SR-U2)
Advisory, not a trust-policy violation: every policy entry blocks deploy, and an error here would fail the next redeploy of already-deployed scripts. ValidationService surfaces it as a non-blocking ScriptCompilation warning.
This commit is contained in:
@@ -69,20 +69,7 @@ public static class RoslynScriptCompiler
|
||||
IEnumerable<MetadataReference>? extraReferences = null,
|
||||
IEnumerable<string>? extraImports = null)
|
||||
{
|
||||
var references = ScriptTrustPolicy.DefaultReferences.ToList();
|
||||
if (extraReferences != null)
|
||||
references.AddRange(extraReferences);
|
||||
|
||||
var imports = ScriptTrustPolicy.DefaultImports.AsEnumerable();
|
||||
if (extraImports != null)
|
||||
imports = imports.Concat(extraImports);
|
||||
|
||||
var options = ScriptOptions.Default
|
||||
.WithReferences(references)
|
||||
.WithMetadataResolver(CachingScriptMetadataResolver.Instance)
|
||||
.WithImports(imports);
|
||||
|
||||
var script = CSharpScript.Create<object?>(code, options, globalsType, SharedNonLoadingLoader);
|
||||
var script = CreateScript(code, globalsType, extraReferences, extraImports);
|
||||
|
||||
// Diagnostics only — NO emit, NO load. `Script.Compile()` builds the
|
||||
// executor, which emits the PE image and loads it through
|
||||
@@ -104,4 +91,36 @@ public static class RoslynScriptCompiler
|
||||
.Select(d => d.GetMessage())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the design-time <see cref="Script{T}"/> with the trust-model references,
|
||||
/// imports, the shared metadata resolver and the shared non-loading assembly
|
||||
/// loader. Callers must only read its compilation — never run it.
|
||||
/// </summary>
|
||||
/// <param name="code">The C# script source.</param>
|
||||
/// <param name="globalsType">Optional globals type the script binds against.</param>
|
||||
/// <param name="extraReferences">Optional additional metadata references.</param>
|
||||
/// <param name="extraImports">Optional additional namespace imports.</param>
|
||||
/// <returns>The unexecuted script.</returns>
|
||||
internal static Script<object?> CreateScript(
|
||||
string code,
|
||||
Type? globalsType,
|
||||
IEnumerable<MetadataReference>? extraReferences = null,
|
||||
IEnumerable<string>? extraImports = null)
|
||||
{
|
||||
var references = ScriptTrustPolicy.DefaultReferences.ToList();
|
||||
if (extraReferences != null)
|
||||
references.AddRange(extraReferences);
|
||||
|
||||
var imports = ScriptTrustPolicy.DefaultImports.AsEnumerable();
|
||||
if (extraImports != null)
|
||||
imports = imports.Concat(extraImports);
|
||||
|
||||
var options = ScriptOptions.Default
|
||||
.WithReferences(references)
|
||||
.WithMetadataResolver(CachingScriptMetadataResolver.Instance)
|
||||
.WithImports(imports);
|
||||
|
||||
return CSharpScript.Create<object?>(code, options, globalsType, SharedNonLoadingLoader);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user