我已经创建了将IronPython代码嵌入C#的代码
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对问题的评论,感谢他们的到来.