如何以编程方式从“StartUp”开始第二个项目项目在同一个C#解决方案中? [英] How to programmatically start the second project from the "StartUp" project in the same C# solution?

查看:149
本文介绍了如何以编程方式从“StartUp”开始第二个项目项目在同一个C#解决方案中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C#VS 2012解决方案,有两个项目:ProjectA和ProjectB。为了简单起见,这两个项目都是控制台应用程序。



需要首先启动ProjectA,以便将其设置为解决方案的启动项目。当我使用F5在调试器下运行ProjectA时,需要执行一些操作,然后在相同的调试器之前启动ProjectB 。所以如果我在ProjectB的第一行设置断点,调试器应该断开。



有什么办法可以做到吗?目前我使用Process.Start(path_to_projectB.exe),但需要用Process.StartUnderSameDebugger(path_to_projectB.exe)替换。我想使用与ProjectB相同的VS调试器实例。



请注意,我不想在Visual Studio中使用启动多个项目选项。如果我这样做,两个控制台应用程序同时启动(这是不需要的)和在同一个调试器(这是想要的)下。第一个进程必须执行一些东西才能启动第二个进程,这就是为什么我不能使用这种方法。



另外,当我以后停止调试器的两个进程(控制台应用程序从应该关闭ProjectA和ProjectB)

解决方案

Visual Studio团队发布了一个Visual Studio扩展,允许自动附加子进程当前的调试器:介绍子进程调试电源工具



所以你可以从 ProjectA 开始你的 ProjectB Process.Start ,它将自动将调试器附加到第二个进程。



它可以在图库



您还可以检查我的答案此处,了解如何将当前调试器附加到您可能启动的任何进程。请注意,它不会像Visual Studio扩展一样直接,因为调试器将在开始之后被附加


I have C# VS 2012 solution with two projects: ProjectA and ProjectB. Both projects are console applications for the sake of simplicity.

ProjectA needs to be started first so it is set as the "Startup project" for the solution. When I run ProjectA with F5 under debugger there are some operations it needs to performs after which it should start ProjectB under the same debugger. So if I set breakpoint in ProjectB first line, debugger should break.

Is there any way I can do this? Currently I use Process.Start("path_to_projectB.exe") but that needs to be replaced with something like "Process.StartUnderSameDebugger("path_to_projectB.exe")". I want to use the same instance of VS debugger that started ProjectA for ProjectB.

Note that I don't want to use "Start multiple projects" option in Visual Studio. If I do this both console apps are started simultaneously (which is unwanted) and under the same debugger (which is wanted). First process must perform some stuff before it can start second process and that's why I can't use this approach.

Also when I later stop debugger both processes (console apps from ProjectA and ProjectB) should be closed.

解决方案

The Visual Studio team has released a Visual Studio extension that allows automatically attaching child processes to the current debugger: Introducing the Child Process Debugging Power Tool.

So you can start your ProjectB from ProjectA with Process.Start and it will automatically attach the debugger to this second process.

It is available on the Gallery for Visual Studio 2013 and above.

You can also check my answer here for how to attach the current debugger to any process you may start. Note that it would not be as immediate as the Visual Studio extension since the debugger would be attached after the process has started.

这篇关于如何以编程方式从“StartUp”开始第二个项目项目在同一个C#解决方案中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆