I am glad to say “YES”, it is possible and easy.
It will be much easy and clear if we do it together step by step in concrete example.
First of all lets create a test WebControlLibrary project.
Then right click on project and select property.
In the property window navigate to Debug section and switch radio button from “Start Project” (set by default) to “Start external program” and browse for devenv.exe executable of Visual Studio which you are using.
Close the property window and for testing purposes set a breakpoint in RenderContent method.
To start debugging right click on project and select “Debug --> Create New Instance”
Debug process will create an instance of Visual Studio. To test behavior of control you can choose one of your existing web projects or create new one. For now I will create fresh WebSite project. Notice that original version of Visual Studio is in Debug mode. During creation or opening web project I am suggesting to turn off any Add-ins if you are using in Visual Studio. Sometimes those tools are raising exceptions and I don’t see reason to use them during testing of design time behavior of custom control.
Now it will be maybe easier to add our assembly to the Toolbox and use it from there. It will automatically add reference of our assembly. By using Drag and Drop technique it will automatically register assembly on a page .
On Toolbox right click and select “Choose Items”.
Navigate for our assembly by using “Browse” button. Make sure that you are picking debug version of assembly (by default it will be located in Debug folder inside of Bin).
After clicking “OK” on “Choose Toolbox Items” window our custom control (or controls if you have several in project) will appear in Toolbox window of Visual Studio.
Now just find it there, drug and drop to the web page. Switch from “Source” mode of your page editor to “Design” and “the magic will appear” :)
Now add breakpoints you need, step thru code, do the stuff you are usually doing during debugging. Next time you can just run "Debug-->Create New Instance" and just choose created WebSite project.
I hope this information will help you to create nice, professional controls without any bugs :).
Have a fun.


No comments:
Post a Comment