【问题标题】:Resources in net standard library project?网络标准库项目中的资源?
【发布时间】:2019-12-04 21:32:37
【问题描述】:

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

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);
    }
}

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

有什么方法可以将index.js 文件添加到我的网络标准库中并从网络标准库中的Ahrs 文件中运行它吗?

【问题讨论】:

    标签: xamarin .net-standard


    【解决方案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

    【讨论】:

    • 可能是它正在工作/应该工作。根据您的建议,我停止获取文件未找到异常。我确实遇到了另一个错误,但我提出了一个问题:github.com/paulbartrum/jurassic/issues/169
    • 在 Android 上我得到:System.IO.FileNotFoundException: 'Could not find file "/index.js"' - 尽管我使用了new FileScriptSource("index.js") :/
    • 我今天来看看,我怀疑这是因为你构建时它不在同一个程序集中,但我会创建一个虚拟项目并测试它
    猜你喜欢
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多