相关疑难解决方法(0)

在托管(嵌入式)环境中调试IronPython脚本

我正在编写一个嵌入了IronPython(2.0.1)的C#应用​​程序.我们的想法是将部分应用程序暴露给用户编写的IronPython脚本.

我想让用户能够使用Visual Studio Debugger调试由他们编写的脚本.请注意,脚本在托管环境中运行,而不是通过IronPython可执行文件(ipy.exe)运行.

在IronPython组件上有一些Reflector魔术后,我想出了一些让我这样做的东西,但我不确定这是否是规定的方式.基本上我所做的是创建一个"DebugRuntime"对象,将"DebugMode"属性设置为true,然后从"ScriptRuntime"创建一个基于python的"ScriptEngine",我用它来托管.代码如下.

        ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
        setup.DebugMode = true;
        setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));

        ScriptRuntime runtime = new ScriptRuntime(setup);
        ScriptEngine engine = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
Run Code Online (Sandbox Code Playgroud)

现在,当我在托管环境中执行脚本时,使用:

            ScriptSource script = engine.CreateScriptSourceFromFile(path);
            CompiledCode code = script.Compile();
            ScriptScope scope = engine.CreateScope();
            script.Execute(scope);
Run Code Online (Sandbox Code Playgroud)

我可以在脚本文件中放置断点,并在脚本执行时被点击.

那么,有更好/更简单的方法吗?

谢谢

.net debugging ironpython

28
推荐指数
1
解决办法
8794
查看次数

标签 统计

.net ×1

debugging ×1

ironpython ×1