繁体   English   中英

在Visual Studio 2012中有一种在调试C#时使用F#REPL的方法

[英]Is there a way in Visual Studio 2012 to use F# REPL when debugging c#

如果我在ac#程序中有断点,则希望使用F#REPL检查我的代码。 这有可能吗?

您应该能够使用F#REPL调试C#项目-我在调试F#库项目时就执行了,但是C#应用程序/库也可以工作(我认为)。

编译您的C#项目。 在F#互动,参考使用该组件的C# #r指令(见ArthurFSharp的职位)。 在C#代码中的某处插入一个断点。

在Visual Studio中,转到Tools -> Attach to Process 在进程列表中找到Fsi.exe并双击它; 如果您在此处看不到它,请确保Fsi进程已启动(只需在F#Interactive窗口中单击即可)。

在F#Interactive中,执行一些代码,这些代码将达到您设置的断点。 调试器应根据需要停止在断点上执行。 只要调试器没有在某个断点处停止,您还可以在FSI中执行其他代码,例如更改正在运行的C#应用​​程序中的设置。

重要说明:请记住,只要将程序集加载到进程中,Windows就会将其锁定。 这意味着只要FSI打开,您将无法重新编译C#应用程序! 不过,修复很简单-对C#应用程序进行了一些更改并想要重新编译并再次开始测试后,只需在F#Interactive窗口中右键单击并在上下文菜单中单击“重置交互式会话”即可。 该过程将被终止并重新启动,因此您可以重新开始。 (如果您确实忘记了重新启动FSI进程并尝试重新编译应用程序,则编译将比正常情况花费更长的时间,那么您将收到一条错误消息,告知您编译器无法写入输出文件。)

您需要使用#I指令包括项目的路径,然后才能加载程序集并使用它。 然后加载程序集(#r指令),打开名称空间,然后可以调用方法(并检查结果)。

例如 :

using System;

namespace ConsoleApplication1
{
    public class Program
    {
        static void Main(string[] args)
        {
            PrintMessage();
        }

        public static void PrintMessage()
        {
            Console.WriteLine("Hello World!");
        }
    }
}

在F#Interactive中:

> #I "full path to debug directory";;

--> Added 'full path to debug directory' to library include path

> #r "ConsoleApplication1.exe";;

--> Referenced 'full path to debug directory\ConsoleApplication1.exe'

> open ConsoleApplication1;;
> Program.PrintMessage();;
Hello World!
val it : unit = ()

ps:首先需要编译您的项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM