Morse
Morse

Reputation: 9125

API to open file from extension folder

I want to embed a DLL file into VS Code extension and open it runtime when extension is activated.

I can include DLL file into vsix extension easily , but want to know how can I access it at runtime.

While extension debug the current direcory is 'C:\Program Files\Microsoft VS Code'

I guess I can open access the file if I can get current execution direcory and then append path like

var cwd = GetCurrentWorkingDirectory(); //to be found out
var dllPath = vscode.Uri.file(cwd+'\resources\app\extensions\myextension\dist');

Is there an VS Code extension API which will give me current extension root directory or else VS Code installation directory?

Upvotes: 4

Views: 1228

Answers (1)

Morse
Morse

Reputation: 9125

Extension Path can be obtained by context object which is passed to activate function; context.extensionPath which is a string or context.extensionUri

Alternatively,

env.appRoot

It can be accessed like

var cwd = vscode.env.appRoot;

maps to VS Code\resources\app

If system installation C:\Program Files\Microsoft VS Code\resources\app

if User installation %LOCALAPPDATA%\Programs\Microsoft VS Code\resources\app

Upvotes: 5

Related Questions