Visual Studio: How to group partial class files in Solution Explorer

This post shows you how to use the File Nesting extension to group files in Visual Studio 2015, 2017, 2019.

File Nesting helps you automatically nest files based on filenames and allows developers to manually nest and unnest any files.

Opening your Visual Studio, then select Tools =>Extensions and Updates

File Nesting

Searching 'nest file', then download File Nesting.

After you finish downloading the File Nesting, you should close your Visual Studio to begin the installation.

File Nesting supports all versions of Visual Studio 2015, 2017, 2019.

Features

- Manually nest files or un-nest files
- Automatic nested 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)

Partial class allows you to split the definition of a class or a struct, an interface or a method over two or more source files

When working on large projects, spreading a class over separate files enables multiple programmers to work on it at the same time.

Use the partial keyword modifier, as shown here

public partial class Student
{
    public void DoHomeWork()
    {
    }
}

public partial class Student
{
    public Student GetStudentInfo(string id)
    {
    }
}

How to nest interfaces using File Nesting?

You can create Customer, CustomerBase class and ICustomer interface, then you can use the File Nesting tool to group all classes

namespace NestFiles
{
    public partial class Customer : CustomerBase
    {
    }
}
namespace NestFiles
{
    public abstract partial class CustomerBase : ICustomer
    {
    }
}
namespace NestFiles
{
    public interface ICustomer
    {
    }
}

Right-clicking on your file you want to group, then select File Nesting =>Nest item...

file nesting

Selecting your parent class, then click OK

file nesting

You can easily nest and unnest any file.

After you finish nesting, you can can see as the figure below.

file nesting

File Nesting also gives you the option to automatically nest it based on file naming rules. You can easily apply those rules to any file, folder, or an entire project.

VIDEO TUTORIAL