Skip to content

How to run a script using CompilationDependencyResolver? #515

Closed
@dfkeenan

Description

@dfkeenan

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy