Search code examples
.netuser-controlsdesigner

.NET User Control: How to use in VS designer without compiling?


I'm trying to create some tutorial projects, and so that I can share a portion of it between projects, I've made part of it into a user control (included as a .cs file in the project, located in a common project folder). The problem is that unless I compile the project, the designer of the forms that I've added the user control to (drag+drop from toolbox) throw an exception when I open them (after cleaning the project):

Could not find type 'WindowsFormsApplication4.UserControl1'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.

I'm trying to make the project easy to use, so requiring the user to compile it first makes it not. Is there any way to have the designer compile the user control before it's rendered at design-time? (distributing any compiled files is not an option)

Or, can I configure the form designer to display a different object at design-time? A place-holder that will be displayed if the user control is not compiled?


Solution

  • No. The Designer requires any UserControl (really, any Control) to be compiled, as it's actually running the code to display the control.

    You'll have to build the project before the designer will function correctly, or distribute it with the control's assembly pre-built.