我已经创建了在 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)、Visual Studio 的 Python 工具(以及用于 Python 代码的 IronPython Launcher)。我试过从字符串和文件创建脚本源,但调试永远不起作用。
最佳答案
像那样向CreateEngine添加选项
var options = new Dictionary<string, object> { ["Debug"] = true };
_engine = Python.CreateEngine( options );
并在允许调试嵌入式 Python 的调试选项中禁用“仅我的代码”,包括断点和单步执行。
感谢 Pavel Minaev 和 Joe 对问题的评论。
关于c# - 有什么方法可以使用 Visual Studio 和 PTVS 调试 C# 中嵌入的 Python 代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31369279/