有什么方法可以使用 Visual Studio 和 PTVS 调试嵌入在 C# 中的 Python 代码?

Kae*_*ber 3 c# debugging ironpython visual-studio ptvs

我已经创建了在 C# 中嵌入 IronPython 代码的代码

    public ScriptEngine GetEngine() {
        if( _engine != null )
            return _engine;

        _engine = Python.CreateEngine();
        var paths = _engine.GetSearchPaths();
        paths.Add( _pythonPath );
        _engine.SetSearchPaths( paths );

        var runtime = _engine.Runtime;
        runtime.LoadAssembly( typeof( CharacterCore ).Assembly );
        return _engine;
    }

    public IAbility Movement() {
        var engine = GetEngine();
        var script = engine.CreateScriptSourceFromFile( Path.Combine( _pythonPath, "movement.py" ) );
        var code = script.Compile();
        var scope = engine.CreateScope();
        code.Execute( scope );

        return scope.GetVariable( "result" );
    }
Run Code Online (Sandbox Code Playgroud)

在同一解决方案中的单独 Python 项目中使用适当的 Python 代码。代码本身有效,但如果我在 Python 代码中设置断点,则永远不会命中。有没有办法让调试器进入 Python 代码?

我正在使用 Visual Studio 2015 RC(也是 Visual Studio 2013),用于 Visual Studio 的 Python 工具(带有用于 Python 代码的 IronPython Launcher)。我试过从字符串和文件创建脚本源,调试永远不会工作。

Kae*_*ber 5

向 CreateEngine 添加选项,就像这样

var options = new Dictionary<string, object> { ["Debug"] = true };
_engine = Python.CreateEngine( options );
Run Code Online (Sandbox Code Playgroud)

并在调试选项中禁用“仅我的代码”允许调试嵌入式 Python,包括断点和单步调试。

感谢 Pavel Minaev 和 Joe 对问题的评论。