Wednesday 21 November 2012

Improved script to compile and show an modified UserControl inside VisualStudio

Here is an updated version of the example described in the Real-time Programming C# WinForms Controls in VisualStudio's IDE (i.e. without using F5) post.

Inside VisualStudio 2010, after the code (shown at the end of this post) is executed:

1) Make some changes in the target file (in this case O2's ascx_Simple_Script_Editor.cs):

2) when the target file is saved, a compilation process happen for that file
3) if the compilation is successful: display a working version of that UserControl directly on the VisualStudio IDE (in a 'real-time preview pane'):

Which is very useful if they are side by side (notice how the 'CHANGED' value was immediately (i.e. after about 1 sec) shown on the right)

4) If there is a compilation error:

You will see an error in VisualStudio's Error list

And if you save the file with that error,  you will see it a similar error in the 'real-time preview pane'

Here is the code that makes this happen (as executed inside the C# REPL VisualStudio Extension):