August 22, 2005
|
App_Code and Toolbox
|
258 hit(s)
In ASP.NET 2.0, you can put source code for a component into the specially named App_Code folder under your app's root, and ASP.NET will dynamically compile the code. In effect, it works as if you'd compiled the code and put the assembly into the Bin folder, except, of course, that you don't have to compile it. (You can if you want, tho.)
Visual Studio knows about the App_Code folder, too, and if you put a component's source there, and assuming that the component compiles without errors, IntelliSense will know all about it. As far as I'm concerned, this is some Powerfuls Magick.
However. I'm messing around with a custom control at the moment. Works great -- you can write the source in App_Code, and when you register the control, the HTML editor knows all about its attributes and such.
But you can't put it on the Toolbox. To add something to the Toolbox, you have to have a reference to its assembly. In the case of code in the App_Code folder, there is no explicit assembly to reference. So your choices are:- Oh, well.
- Build the VS project, grub around in the temporary folders until you find the dynamically generated assembly, and then reference that. This is, ahem, a hack. And anyway, there's no guarantee that the assembly will always be there. On the contrary, it's guaranteed not to always be there. Not, ahem, a supported scenario.
- Create a client project where you define the control, and then add a client project reference, which gives you access to the control's assembly. Note that you can't do this in Visual Web Developer Express Edition, because you can't create multi-project solutions.
- Create the control and compile it manually (with the SDK compiler, for instance), add a reference to the .dll, and party away.
I think those are the options. If I missed one, perhaps someone can leave a comment.
|