通过nuget 搜索JavaScript Engine,得到结果后,安装JS Engine Switcher:v8
// 实例化
JavaScriptEngineSwitcher.V8.V8JsEngine engine = new JavaScriptEngineSwitcher.V8.V8JsEngine();
// 加载脚本
var scriptStr= @"var hash2 = function(a,b){
return a+b}";
engine.Execute(script);
// 调用js方法
var result = engine.CallFunction<string>("hash2", 1, 2);
System.Console.WriteLine(result);