简体   繁体   English

如何从Visual Studio 2013调试.NET控制台应用程序

[英]How to debug .NET console application from Visual Studio 2013

I've created a .NET 4.5 console application (an .exe file) with c# that processes some data in various files. 我用c#创建了一个.NET 4.5控制台应用程序(.exe文件)来处理各种文件中的一些数据。 The whole thing runs in less than one second. 整件事不到一秒钟就完成了。 I have a problem with a testing version of the .exe that I'd like to step through in the Visual Studio 2013 debugger using particular input files (the filenames are passed as command line arguments). 我有一个.exe的测试版本的问题,我想在Visual Studio 2013调试器中使用特定的输入文件(文件名作为命令行参数传递)。 I can't do an "Attach to process..." since the process has completed too quickly to attach to it. 我不能做“附加到进程...”,因为该过程已经完成得太快而无法附加到它上面。 How do I debug in this case. 在这种情况下如何调试。

Note that I'm from the python world, and the python equivalent of what I'm trying to do is python -m pdb pdb_script.py . 请注意,我来自python世界,而我正在尝试做的python相当于python -m pdb pdb_script.py

Thanks for any advice! 谢谢你的建议!

Right click on your project and go to "properties". 右键单击您的项目并转到“属性”。

Then select the "debugging" tab on the left-hand side. 然后选择左侧的“调试”选项卡。

There's a box where you can input the desired command line arguments for use when running in debug mode. 有一个框,您可以在其中输入所需的命令行参数,以便在调试模式下运行时使用。

EDIT: If you're asking how to start the debugger, then add some breakpoints to your code, then right click on the project in your solution and pick Debug > Start New Instance. 编辑:如果您正在询问如何启动调试器,那么在代码中添加一些断点,然后右键单击解决方案中的项目并选择Debug> Start New Instance。

Alternatively you can right click and choose "Set as Startup Project", after which you can start debugging with F5 or the "Start" button at the top of the UI. 或者,您可以右键单击并选择“设置为启动项目”,之后您可以使用F5或UI顶部的“开始”按钮开始调试。

Add the following line in your code: 在代码中添加以下行:

System.Diagnostics.Debugger.Break();

This will allow you to debug your application before it ends. 这将允许您在应用程序结束之前调试它。

In Visual Studio, you can add commandline arguments before starting a debugging session by right-clicking your project, selecting properties and then going down to the debug tab. 在Visual Studio中,您可以在开始调试会话之前添加命令行参数,方法是右键单击项目,选择属性,然后转到调试选项卡。

Then you can start it in Visual Studio with f5 然后,您可以使用f5在Visual Studio中启动它

If that's too much trouble (because you are going to change the arguments a lot), you could do something like adding a Console.ReadLine to your program at the beginning that will give you a change to attach a debugger. 如果这太麻烦了(因为你要经常更改参数),你可以做一些事情,例如在开始时向你的程序添加一个Console.ReadLine ,它会给你一个连接调试器的更改。 You could even have an extra command line argument for debugging that will only pause for you to attach the debugger if you pass that argument. 您甚至可以有一个额外的命令行参数用于调试,只有在您传递该参数时才会暂停以附加调试器。

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

相关问题 ASP.Net Kestrel无法从Visual Studio加载控制台,如何调试该问题? - ASP.Net Kestrel not loading up console from Visual Studio, how can I debug the issue? 如何从Visual Studio 2017中的.NET Framework 4.5控制台应用程序引用.NET标准库? - How Do You Reference a .NET Standard Library from a .NET Framework 4.5 Console Application in Visual Studio 2017? 如何在Linux中的Mono下调试Visual Studio .NET应用程序? - How to debug Visual Studio .NET application under Mono in Linux? 如何在Visual Studio 2010中调试从另一个进程启动的C#.NET应用程序 - How to debug a C# .NET application in Visual Studio 2010 that is started from another process 在Visual Studio 2013中为.NET 3.5调试添加调试符号 - Add debug symbols for .NET 3.5 Debugging in Visual Studio 2013 如何使用Visual Studio 2019社区创建.NET Core 3控制台应用程序? - How to create a .NET Core 3 console application with Visual Studio 2019 Community? Visual Studio 2013调试崩溃 - Visual Studio 2013 debug crash Visual Studio 2013中的控制台模板不存在吗? - Console template in Visual studio 2013 not there? Web解决方案中的Visual Studio C#调试控制台应用程序 - Visual Studio C# debug console application that is part of web solution Visual Studio 2013自定义测试适配器:如何调试? - Visual Studio 2013 custom Test Adapter: how to debug?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM