在托管/嵌入式C#中调试IronPython

时间:2019-04-03 19:35:10

标签: c# visual-studio ironpython visual-studio-debugging visual-studio-2019

我正在开发asp.net核心应用程序+ IronPython。 但是我遇到了调试问题...

例如,我有以下代码:

Dictionary<string, object> options = new Dictionary<string, object>();
options["Debug"] = true;
ScriptEngine engine = Python.CreateEngine(options);

// output redirect
var eIO = engine.Runtime.IO;

var errors = new MemoryStream();
eIO.SetErrorOutput(errors, Encoding.Default);

var result = new MemoryStream();
eIO.SetOutput(result, Encoding.Default);

// execute script
ScriptScope scope = engine.CreateScope();
scope.SetVariable("testGlobalVar", 10);
engine.ExecuteFile(ScriptPath, scope);

在python文件中

some = "Test"

print(Test)
print("We have ->", testGlobalVar)

它可以正常工作,但是当通过C#运行它时,我不知道如何在python文件中设置断点并在Visual Studio Pycharm(无论如何)中逐步调试它。

我发现了this question,但几乎完全没有用。我正在python文件中设置断点,什么也没发生。

1 个答案:

答案 0 :(得分:1)

因为如前所述,它在没有调试模式的情况下也可以正常工作。我认为为什么在调试模式下不会遇到断点的原因是调试器找不到它。

Go=>Debug=>Options =>取消选中Enable Just My Code来检查是否有帮助。

注意:

  1. 将.net核心应用设置为启动项目

  2. 如果取消选中Enable Just My Code无济于事,建议您转到tools->Import/Export Settings->reset all settings,然后再次取消选中Enable Just My Code

此后,可以按以下方式命中断点:

enter image description here

此外:我使用.net控制台应用程序进行再现和测试,但是我认为它具有与Web应用程序类似的行为。任何更新都可以随时与我联系:)