网络标准库项目中的资源?

时间:2019-12-03 09:42:24

标签: xamarin .net-standard

我打算在Xamarin应用程序中使用javascript传感器融合库-可能还会在手表项目中使用。在我的网络标准库中,我有:

enter image description here

Ahrs文件包含:

public class Ahrs
{
    static ScriptEngine engine = new ScriptEngine();
    static FileScriptSource fileScript = new FileScriptSource("./index.js"); // <-- invalid file path
    public static double Run()
    { // file notfound
        engine.Evaluate(fileScript);
        return engine.CallGlobalFunction<double>("update", 0, 0, 0, 1, 1, 1);
    }
}

...我试图用Jurassic在我的update文件中调用方法js

是否可以通过某种方式将index.js文件添加到我的网络标准库中,并从Ahrs文件中运行它,全部在网络标准库中?

1 个答案:

答案 0 :(得分:1)

如果我使用路径"index.js"而不是"./index.js",似乎对我有用

public class Ahrs
{
    static ScriptEngine engine = new ScriptEngine();
    static FileScriptSource fileScript = new FileScriptSource("index.js"); // <-- valid file path
    public static double Run()
    { // file found
        engine.Evaluate(fileScript);
        return engine.CallGlobalFunction<double>("update", 0, 0, 0, 1, 1, 1);
    }
}  

我还设置了javascript文件的属性:

  • 构建操作:Embedded resource
  • 复制到输出目录:Copy always

enter image description here