I was shown a nice little trick today by a collegue who was trying to debug a Windows Installer CustomAction. The problem of course is that you can't debug the code because it is being launched and controlled by the Windows Installer/MSI. The trick is to add the line below somewhere in the code:
System.Diagnostics.Debugger.Break();
When this line is executed an "exception" is thrown, which launches the Visual Studio dialog asking you if you wish to debug the process as there is an exception. Now you can simply attach to your Visual Studio session and debug your code as normal! Nice trick, that after nearly 5 years of working with .NET, I had not come across.
It's worth noting that execution will continue after the Break method is called, so you need to have a normal breakpoint ready when you attach to the VS session.
Remember Me
Page rendered at 2/10/2012 4:18:48 AM (New Zealand Standard Time, UTC+12:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.