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条回答
疯言疯语
2楼-- · 2020-06-01 06:50

If I understand correctly, Macro may be answer:

in Vs:

  1. Tools->Macros->record TemporarilyMacro (Ctrl+shift+r)
  2. Attach VS to process as usual (ctrl+alt+p)
  3. Stop recording macro (ctrl+shift+r)
  4. Go to View->Other Windows->Macro Explorer (CTRL+F8)
  5. find your Temporarily Macro (somewhere in MyMacros->RecordingModule) and rename it
  6. Now, go to Tools->Options->Keyboard and find your macro (in "Show Command containing write name of you macro)
  7. in "Press Shortcut keys" bind it to some key shortcut (i have my macro in CTRL+SHIFT+K ;))
  8. Push OK
  9. Be Happy
查看更多
▲ chillily
3楼-- · 2020-06-01 06:53

Sample howto start a process and attach it to Visual Studio 2010 with EnvDTE(Version is relevant).

//c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\EnvDTE.dll
using Process = EnvDTE.Process;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + @"\YourProcess.exe";
//Start the process
p.Start();
//Wait for process init
System.Threading.Thread.Sleep(1000);

bool attached = false;
//did not find a better solution for this(since it's not super reliable)
for (int i = 0; i < 5; i++)
{
    if (attached)
    {
        break;
    }
    try
    {
        EnvDTE.DTE dte2 = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.10.0");
        EnvDTE.Debugger debugger = dte2.Debugger;
        foreach (Process program in debugger.LocalProcesses)
        {
            if (program.Name.Contains("YouProcess.exe"))
            {
                program.Attach();
                attached = true;
            }
        }
    }
    catch (Exception ex)
    {
        //handle execption...
    }
}
查看更多
Deceive 欺骗
4楼-- · 2020-06-01 06:55

Here is a detained article that explains how to do this...You can customize this macro.

http://sivablogz.wordpress.com/2013/04/08/running-an-application-and-attaching-to-the-process-with-a-macro-in-visual-studio/

查看更多
狗以群分
5楼-- · 2020-06-01 07:01

Personally I prefer to use Debugger.Launch() as suggested here in this thread, because it doesn't need for references to the DTE (that's IDE-specific and must be explicitly referenced into the project to be used)

查看更多
贼婆χ
6楼-- · 2020-06-01 07:05

Configure your solution for multi project start up. I do this for a similar application. VS launches the WCF and client automatically and I can set break points in either.

The start-up order is the order in which you select the projects.

Right mouse click on your solution and select 'choose startup projects'. Then select multiple startup projects and select the projects.

查看更多
叛逆
7楼-- · 2020-06-01 07:08

Have you tried using the WCFSvcHost.EXE that comes with Visual Studio to launch the BLL and DAL service? There is a help file with it. The help file states it best, "Windows Communication Foundation (WCF) Service Host (wcfSvcHost.exe) allows you to launch the Visual Studio debugger (F5) to automatically host and test a service you have implemented. You can then test the service using WCF Test Client (wcfTestClient.exe), or your own client, to find and fix any potential errors." The default installation is C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE. You can configure it to use your MainUI app as the client. The help file WcfSvcHost.chm in the same directory has a section for using a custom client under the Scenarios for using ECF Service Host. If you rather here is the link to help on MS web site: Using WCF Service Host (wcfSvcHost.exe).

查看更多
登录 后发表回答