Visual Studio 2010 Automatic Attach To Process

后端 未结 10 2237
谎友^
谎友^ 2021-02-07 08:51

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 commun

相关标签:
10条回答
  • 2021-02-07 09:29

    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).

    0 讨论(0)
  • 2021-02-07 09:32

    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
    0 讨论(0)
  • 2021-02-07 09:34

    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.

    0 讨论(0)
  • 2021-02-07 09:42

    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)

    0 讨论(0)
  • 2021-02-07 09:43

    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...
        }
    }
    
    0 讨论(0)
  • 2021-02-07 09:44

    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.

    0 讨论(0)
提交回复
热议问题