JsScriptTaskExecutor.Net 1.0.1

dotnet add package JsScriptTaskExecutor.Net --version 1.0.1
                    
NuGet\Install-Package JsScriptTaskExecutor.Net -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsScriptTaskExecutor.Net" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JsScriptTaskExecutor.Net" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="JsScriptTaskExecutor.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JsScriptTaskExecutor.Net --version 1.0.1
                    
#r "nuget: JsScriptTaskExecutor.Net, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JsScriptTaskExecutor.Net@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JsScriptTaskExecutor.Net&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=JsScriptTaskExecutor.Net&version=1.0.1
                    
Install as a Cake Tool

JsScriptTaskExecutor.Net

A .NET library powered by the Microsoft ClearScript V8 engine to safely execute JavaScript scripts, with strongly-typed inputs/outputs, timeout control, and dynamic library injection. It is particularly useful for executing script tasks in BPMN or workflow engines where dynamic logic is required.

Features

  • Execute JavaScript using Microsoft ClearScript V8 engine
  • Strongly-typed input/output variable handling (primitives, objects, lists)
  • Inject reusable JavaScript libraries at runtime
  • Timeout control to prevent long-running or stuck scripts
  • Type-safe conversions between script and .NET types

Installation

Install via NuGet:

dotnet add package JsScriptTaskExecutor.Net

Or using the NuGet Package Manager:

PM> Install-Package JsScriptTaskExecutor.Net

🛠 Quick Start (Package Usage)

  1. Register the service in your Program.cs:
using ScriptTaskExecutor.Engine;

var builder = WebApplication.CreateBuilder(args);

// Configure ScriptTaskExecutor with path to JS libraries
builder.Services.AddScriptTaskExecutor(librariesPath: "path/to/your/js/libraries");

var app = builder.Build();

This sets up the IScriptTaskExecutor service for injection into controllers or other services.

  1. Basic Usage Example
using ScriptTaskExecutor.Engine.DataTypes;
using ScriptTaskExecutor.Engine.Executors;
using ScriptTaskExecutor.Engine.Models;

public class ScriptService
{
    private readonly IScriptTaskExecutor _executor;

    public ScriptService(IScriptTaskExecutor executor)
    {
        _executor = executor;
    }

    public async Task RunScript()
    {
        var context = new ScriptExecutionContext
        {
            Script = "result = input1 + input2;",
            Inputs = new Dictionary<string, (DataTypesEnum Type, object? DefaultValue)>
            {
                { "input1", (DataTypesEnum.Int32, 5) },
                { "input2", (DataTypesEnum.Int32, 10) }
            },
            Outputs = new Dictionary<string, DataTypesEnum>
            {
                { "result", DataTypesEnum.Int32 }
            },
            TimeoutMs = 5000
        };

        var outputs = await _executor.ExecuteScript(context);
        Console.WriteLine($"Result: {outputs["result"]}"); // Output: 15
    }
}

⚠️ Important — Declaring Output Variables in JavaScript

Any JavaScript variable you expect to retrieve as an output variable must be declared with var.

In JavaScript, let and const are block-scoped and are not attached to the global object, so they will not be accessible from the .NET side after script execution.

Why this is required

When the V8 engine executes your script, only variables declared with var at the top level are added as properties of the global object. Variables declared with let or const live in the script’s internal scope and are not visible outside the script.

✅ Example (works)

var result = inputValue * 2;

❌ Example (will not work)

let result = inputValue * 2;
const result = inputValue * 2;

💡 If you must use let or const

Explicitly assign the value to the global object:

let result = inputValue * 2;
globalThis.result = result; // Now accessible from C#

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 333 11/24/2025
1.0.0 395 8/29/2025