File Nesting also gives you the option to automatically nest based on file naming rules. You can then apply those rules to any files, folders or entire projects.

First, You need to install File Nesting extension by selecting Tools->Extensions and Updates from Visual Studio 2013/2015/2017

install file nesting

Click Download button to install the file nesting extension

install file nesting

Click Install button, then restart your visual studio

Now, Create Student class, StudentRepository class and IStudent interface as below

file nesting

To use the file nesting extension, you need to right click on class that you want to group file then select File nesting->Nest item...

file nesting

You will also see

file nesting

Select your parent class, similar for StudentRepository class

file nesting

If you open up the .csproj file, you can see that this is set out as follows:

<ItemGroup>
    <Compile Include="IStudent.cs">
      <DependentUpon>Student.cs</DependentUpon>
    </Compile>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Student.cs" />
    <Compile Include="StudentRepository.cs">
      <DependentUpon>Student.cs</DependentUpon>
    </Compile>
</ItemGroup>

Features File Nesting

  • Manually nest files
  • Manually un-nest files
  • Auto-nesting based on naming conventions
  • Option to enable auto-nesting when files are added or renamed
  • Options to specify which naming conventions to apply
  • Keyboard shortcut for manual nesting (Ctrl+Alt+N)