Closed
Description
Hi,
I am trying to using the CompilationDependencyResolver for my own script runner but the scripts don't compile due to it not knowing what System.Object
or System.Void
is.
I naively tried:
Dotnet.Script.DependencyModel.Logging.LogFactory logFactory = (t) => (l, m, e) => Log.WriteLine(m);
dependencyResolver = new CompilationDependencyResolver(logFactory);
//...
using var file = File.Open(scriptFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var loader = new InteractiveAssemblyLoader();
var dependencies = dependencyResolver.GetDependencies(path, new[] { scriptFileName }, true, "netcoreapp3.1");
var assemblyReferences = dependencies
.SelectMany(d => d.AssemblyPaths)
.ToArray();
var scriptOptions = ScriptOptions.Default
.WithFilePath(scriptFileName)
.WithMetadataResolver(new NuGetMetadataReferenceResolver(ScriptOptions.Default.MetadataResolver))
.WithReferences(assemblyReferences)
//.WithReferences(AssemblyReferences) - I was manually adding assemblies in the past
.WithEmitDebugInformation(enableDebugging);
var script = CSharpScript.Create<SkiaPadScript>(file, scriptOptions, assemblyLoader:loader);
ScriptState<SkiaPadScript> result = await script.RunAsync();
My application targets netcoreapp3.1
.
The script I am testing with is:
#! "netcoreapp3.1"
#r "nuget: SkiaPad.Scripting,1.0.0"
#r "nuget: Newtonsoft.Json,12.0.3"
using System;
using SkiaSharp;
using SkiaPad.Scripting;
using SkiaPad.Scripting.Mathematics;
using Newtonsoft.Json;
var paint = new SKPaint();
paint.Color = SKColors.Purple;
public void Start(ScriptContext context, SKCanvas canvas, SKRect bounds)
{
Console.WriteLine(JsonConvert.SerializeObject(paint));
}
public void Draw(ScriptContext context, SKCanvas canvas, SKRect bounds)
{
canvas.Clear(SKColors.Yellow);
}
public void Dispose()
{
}
Any help would be greatly appreciated.
Thanks,
Daniel
Metadata
Metadata
Assignees
Labels
No labels