.NET Framework General Reference
codeSubDirectories Element for compilation (ASP.NET Settings Schema)

Defines an ordered collection of subdirectories that contains files to compile at run time.

This element is new in the .NET Framework version 2.0.

<configuration> Element
  system.web Element (ASP.NET Settings Schema)
    compilation Element (ASP.NET Settings Schema)
      codeSubDirectories Element for compilation (ASP.NET Settings Schema)
<codeSubDirectories>
   <add />
  
/>

The following sections describe attributes, child elements, and parent elements.

Attributes

None.

Child Elements

Element

Description

add

Optional element.

Adds a subdirectory to the collection of subdirectories that contain files to compile at run time.

Parent Elements

Element

Description

configuration

Specifies the required root element in every configuration file that is used by the common language runtime and the .NET Framework applications.

system.web

Specifies the root element for the ASP.NET configuration section.

compilation

Configures all compilation settings that ASP.NET uses to compile applications.

The codeSubDirectories element defines an ordered collection of subdirectories that contain files to compile at run time.

Subdirectory names are relative to the App_Code directory.

The build order is inferred from the top-down order of the codeSubDirectories collection. The App_Code directory is built last. However, there are no build order dependencies, therefore that the build order is not significant.

Default Configuration

There is no default codeSubDirectories element configured for ASP.NET.

The following code example shows how to define an ordered collection of assembly subdirectories. The subdirectories are listed in the order that the code must be compiled, which is a function of your code dependencies.

<configuration>
   <system.web>
      <compilation>
         <codeSubDirectories>
           <add directoryName="mySubDir1"/>
           <add directoryName="mySubDir2"/>
           <add directoryName="mySubDir3"/>
         </codeSubDirectories>
      </compilation>
   </system.web>
</configuration>

Configuration section handler

CompilationSection

Configuration member

CodeSubDirectories()()()

CodeSubDirectoriesCollection

Configurable locations

Machine.config

Root-level Web.config

Application-level Web.config

Virtual or physical directory–level Web.config

Requirements

Microsoft Internet Information Services (IIS) version 5.0, 5.1, or 6.0

The .NET Framework version 2.0

Microsoft Visual Studio 2003 or Visual Studio 2005

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
clear and remove elements do not work      bdukes   |   Edit   |   Show History
The clear and remove subelements of codeSubDirectories do not actually work. See https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103012 for the issue. There is no way to remove code sub directories, you must maintain a list of all directories from a parent application to all sub-applications.
Not possible to add subfolders more then one level below App_Code      AbelB   |   Edit   |   Show History
It is not possible to add a subdirectory higher then one level below the App_Code directory. When you have a setting like the following:

<codeSubDirectories>
<add directoryName="test-folder\test-child" />
</codeSubDirectories>

This will cause your compiler to complain with the error message
Invalid subdirectory 'test-folder\test-child'. Only subdirectories directly under the App_Code directory are allowed.
If you use this feature to delay compilation and avoid errors such as the rather infamous:
The files '/App_Code/Class2.vb' and '/App_Code/Class1.cs' use a different language, which is not allowed since they need to be compiled together.
note then that all subdirectories under the added run-time compilation directory will be allowed to have different language content, but each mapped directory must have the same language still.

Adding directories in this manner will also speed up compilation time if you have many class files under App_Code. For more information on best practices using this setting see http://abel.metacarpus.com/aps.net-codesubdirectories.

(All the above was tested using Visual Studio 2008 using .NET Runtime 3.5. Error messages and behavior may differ for other versions of Visual Studio and/or the runtime.)
Tags What's this?: Add a tag
Flag as ContentBug
Processing
Page view tracker