Guido
Guido

Reputation: 958

How to call a dll when developping a VS Code Extension

I try to write an SQL beautifier as VS Code extension. The SQL beautifier engine/parser is already availabe as .dll, because I wrote it a couple of years ago in C# (more than 10K lines of code). As VS code extensions are written in typescript / Javascript it looks like you can not call a dll or maybe I am too stupid!? Do you know how I can call my dll out of a VS code Extension? Thx.

Upvotes: 3

Views: 2501

Answers (2)

mesutpiskin
mesutpiskin

Reputation: 1927

You can run your dll, jar or exe files by putting them in assets folder. It can be done using child_process.

const vscode = require('vscode');
const path = require('path');
const child_process = require('child_process')

let myAppPath = vscode.Uri.file(path.join(context.extensionPath, "assets/myapp.dll"));
let execCommand = `dotnet ${myAppPath.fsPath}`;
child_process.exec(execCommand, (err, stdout, stderr) => {
    if (stdout) {
        vscode.window.showInformationMessage(stdout);
    }
    if (stderr) {
        vscode.window.showWarningMessage(stderr);
    }
    if (err) {
        vscode.window.showErrorMessage("" + err);
    }                           
});

Upvotes: 1

basarat
basarat

Reputation: 275957

because I wrote it a couple of years ago in C#

You can invoke C# code from JavaScript (TypeScript) using Edge

More

Official docs https://github.com/tjanczuk/edge

Upvotes: 1

Related Questions