How do I attach Visual Studio to a process that is not started yet?

前端 未结 8 1200
不思量自难忘°
不思量自难忘° 2020-12-02 07:41

I have .NET program that can\'t be run from Visual Studio for some reasons (Excel file created from an Excel 2010 template project) for which I need to debug startup events.

8条回答
  •  感动是毒
    2020-12-02 07:55

    You can start the debugger from your code via

    public static void Main(string[] args)
    {
      System.Diagnostics.Debugger.Launch();
    }
    

    But don't for get to remove this line before shipping your application. Maybe you want to use compiler flags to be sure:

        public static void Main(string[] args)
        {
          #if debug
          System.Diagnostics.Debugger.Launch();
          #endif
        }
    

提交回复
热议问题