Thursday, December 20, 2007

Language-specific Code Compilation in App_Code

App_Code folder is the default location to add your code files for your ASP.NET project. You may have the situation when you want to add mixed code files written in different languages i.e C# or VB.Net and you need to include these mixed files in the project compilation. The question: Can I have mixed files some written in C# and others in VB.NET in the App_Code folder? Yes, you can but in limitation. First, you will have to add different folders for each language-specific code. Then, in web.config add an entry for each folder inside CodeSubDirectories tag.

<?xml version="1.0"?>
<compilation debug="true">
<add directoryName="CSharpFolder"/>
<add directoryName="VBFolder"/>
If the folder you added to codeSubDirectories tag doesn't physically exist, you will have a compilation error.
The code subdirectory '/MyProject/App_Code/CSharpFolder/' does not exist. E:\Projects\MyProject\web.config