ASP.NET 2.0: Use VB.NET and C# within the App_Code folder

30. March 2006

When I was creating my new blog site (this site your looking at), I chose to write it in C#. I had a problem with the App_Code folder because I had some code in VB.NET code and some C# code I needed to put in there. I didn't want to rewrite my VB.NET code in the App_Code folder just so I could write the rest of the code for the site in C#.

Luckily, the ASP.NET Team had already thought about just this kind of circumstance. They implemented a way to partition the App_Code folder into sub-folders, one for each set of code files written in the same programming language. Awesome, I didn't have to spend a couple hours converting code from VB.NET to C#!

Even if you don't use multiple different programming languages for your code files in the App_Code folder, you could use this feature to organize your sets of related code files into sub-folders.

Step 1: Add the following lines to the web.config


<configuration>

    <system.web>

        <compilation>

            <codeSubDirectories>

                <add directoryName="VB_Code"/>

                <add directoryName="CS_Code"/>

            </codeSubDirectories>

        </compilation>

    </system.web>

</configuration>

Step 2: Create a sub-folder in the App_Code folder for each language you want to support.
For Example:
/App_Code/VB_Code
/App_Code/CS_Code

Step 3: Place your VB.NET code in the VB_Code folder and place C# code in the CS_Code folder.

General, vb.net, C#



Comments

Vincent
Vincent
4/9/2006 1:19:00 AM #
Good explaination given for using both languages VB and C# in the appcode folder. along with clear documentation on how to write stuff in the web.config file. Steps format of document was very useful.
Thanks buddy
Jersey
Jersey
5/5/2006 2:50:00 AM #
Great! This is what I was looking for and it works!

Thank you very much.
Serna
PkingROch
PkingROch
6/16/2006 12:16:00 PM #
Unfortunately, Remove is part of the schema in the documentation, but it won't compile...
6/16/2006 12:51:00 PM #
Remove? What would you use Remove for with this? You don't even need to use Remove.
6/22/2006 8:35:00 PM #
Thanks! Timely, easy and very useful.
The Coder
The Coder
7/10/2006 6:05:00 PM #
Good work! Just what I needed.
manisha
manisha
7/16/2006 10:13:00 AM #
excellent and easy for understanding for us who are now studying the asp.net
vnguyen
vnguyen
7/16/2006 10:34:00 AM #
Is there any way not to use App_Code at all? I migrate my project from 03 and it keeps separating some asp.net code files (.aspx.vb) from the aspx file and put in App_code. Same thing happened with my report files. Any suggestion?
mtran
mtran
8/17/2006 1:39:00 PM #
Thanks for the instructions how to setup for both languages.
All Aboard
All Aboard
10/4/2006 12:31:00 PM #
C'mon get aboard the love train!
Mehdi
Mehdi
12/29/2006 12:32:00 PM #
I have a huge app_code folder with many sub-folders. When I make a change in one of the files in App-code folder, the build takes too long. It rebuids all the sub-folders in app_code. Is there a way to get it to build only the changed folder?

Thanks
faizer
faizer
12/29/2006 5:09:00 PM #
Thanks a lot! It was a pain to find a way around this problem... But with your help it works now! Thanks again!!! Smile
12/29/2006 7:35:00 PM #
Actually, the only solution to your problem is to pull out some or all of you classes in the App_Code and compile them into a DLL in the Bin folder. The App_Code folder isn’t really meant to contain large amounts of code.
Ajay
Ajay
12/30/2006 5:16:00 AM #
This trick is useful. there are senarios when we need both in App_Code
1/19/2009 1:09:47 PM #
Pingback from keyongtech.com

dll with both C# and VB | keyongtech
10/22/2009 10:24:45 AM #
Pingback from pthok.wordpress.com

C# and VB.NET in the same App_Code folder « Peter Thok
12/5/2009 9:02:02 PM #
Pingback from briankirsten.com

links for 2009-12-05
Comments are closed