有什么方法可以调试c#中嵌入的Python代码与Visual Studio和PTVS
本文关键字:代码 Python Visual PTVS Studio 方法 什么 调试 | 更新日期: 2023-09-27 18:02:22
我已经创建了在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" );
}
与相同解决方案中单独的Python项目中的适当Python代码。代码本身可以工作,但是如果我在Python代码中设置了一个断点,它永远不会被击中。有没有一种方法有一个调试器步骤进入Python代码?
我使用的是Visual Studio 2015 RC(也是Visual Studio 2013), Python Tools for Visual Studio(与IronPython Launcher for Python代码)。我试过从字符串和文件创建一个脚本源,调试从来没有工作过。
为CreateEngine添加选项,如
var options = new Dictionary<string, object> { ["Debug"] = true };
_engine = Python.CreateEngine( options );
和在Debug选项中禁用"Just my code"允许调试嵌入式Python,包括断点和步进。
感谢Pavel Minaev和Joe对问题的评论。