Visual Studio 2010 Automatic Attach To Process

2020-06-01 06:33发布

I am using visual studio 2010, my application has a multiu layer architect,

MainUI, WCFService, BLL and DAL

My MainUI communicated to WCF and WCF further communicates to BLL and DAL, whenever i need to debug BLL and DAL, i first need to attach WCF as a process in Visual studio(everytime). How could i can save myself from this hassle.

How could i set up visual studio in a way that i automatically attach to the service automatically and i could debug my application easily.

Thanks

10条回答
Deceive 欺骗
2楼-- · 2020-06-01 07:10
  1. In the properties page for the wcf service project, select the Web tab.
  2. Select 'Start External Program' for the start action, and choose MainUI.exe.
  3. Set the working directory as the folder that MainUI.exe is in (probably a bin folder).
  4. Set a break point and press f5 to start debugging.
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-06-01 07:12

Have you tried System.Diagnostics.Debugger.Launch() in your service you would like the debugger to attach to?
http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.launch.aspx

查看更多
Root(大扎)
4楼-- · 2020-06-01 07:13

If this is for a self-hosted WCF windows service, you need to make your WCF service host configurable to either run in console or as a windows service. When you have run in console turned on, you can start debugging from visual studio.

Create an app setting called "RunInConsole." In your service host startup method, have the following code:

public class MyWindowsService : ServiceBase
{
    public static void Main(string[] args)
    {
        // if configuration says to run in the console, run the service in a console app. otherwise, use windows
        // service to host application
        if (ConfigurationManager.AppSettings["RunInConsole"] == "true")
        {
            using (ServiceHost host = new ServiceHost(typeof(MyService)))
            {
                host.Open();
                Console.WriteLine("Press <Enter> to terminate the Host application.");
                Console.ReadLine();
            }
        }
        else
            ServiceBase.Run(new MyWindowsService ());
    }

}

On all environments you deploy to, you'd always have this config setting set to false or else the service will fail to start, but when debugging locally you'd set it to true.

查看更多
神经病院院长
5楼-- · 2020-06-01 07:16

Try using System.Diagnostics.Debugger.Break() in the code. If a debugger is not attached, then running that code will ask to attach a debugger and you can choose the existing instance.

查看更多
登录 后发表回答