Create C# nested files in Visual Studio

Introduction

Microsoft Visual Studio supports nested files, which are usually appsettings.json. Other file types are supported by creating a file named .filenesting.json in the root of a C# project.

Example

In the Models folder, …


This content originally appeared on DEV Community and was authored by Karen Payne

Introduction

Microsoft Visual Studio supports nested files, which are usually appsettings.json. Other file types are supported by creating a file named .filenesting.json in the root of a C# project.

Example

In the Models folder, a Person class is a partial class separated into three files.

Shows from VS2022 Solution Explorer the the person files

To nest the three files created in the root folder of the project a file named nesting.json as shown below.

{
  "help": "https://go.microsoft.com/fwlink/?linkid=866610",
  "root": true,
  "dependentFileProviders": {
    "add": {
      "fileToFile": {
        "add": {
          "Person.Notification.cs": [
            "Person.cs"
          ],
          "Person.Sets.cs": [
            "Person.cs"
          ]
        }
      }
    }
  }
}

Note the organization for each node: a class file with the base file name, a descriptor, and an extension, followed by the base file name. The results are shown below.

From Solution Explorer shows the nested Person class

Using Copilot prompt files to create .filenesting.json

By creating a prompt file Copilot can create a nesting file.

For this example partial classes are targeted under the Models folder.

  • Under the root folder of the Visual Studio solution, add a file named NestedPartialClasses.prompt.md under the folder .github\prompts (see example in provided source code)

  • Add the following instructions

  1. If there is a Models folder find all partial classes in it.
  2. Collect each partial class files
  3. Create in the root folder of the current project a file named .filenesting.json
  4. In this file, create a JSON structure that nests all the partial class files under their main class file. The main class file will have a single period in the file name.
  • Open Copilot Chat window.
    • Select Agent mode
    • Select the project
    • Select the prompt file
    • Select press enter

Copilot reads the prompt file instructions and executes. Once finished, accept the new file if it is correct, which it should be. Examine that the class is now nested under Solution Explorer.

Chat window targeting the project PromptFilesExampleApp1.

Chat window

If the partial classes are in a different folder, adjust the instructions in the prompt file.

Source code

Source code

  • Prompt file: Solution root folder .github\prompts\NestedPartialClasses.prompt.md
  • Sample project: PromptFilesExamplesApp1

✔️ Note the following in the project file for permitting the use of the field keyword.

<LangVersion>preview</LangVersion>


This content originally appeared on DEV Community and was authored by Karen Payne


Print Share Comment Cite Upload Translate Updates
APA

Karen Payne | Sciencx (2025-08-22T22:26:24+00:00) Create C# nested files in Visual Studio. Retrieved from https://www.scien.cx/2025/08/22/create-c-nested-files-in-visual-studio/

MLA
" » Create C# nested files in Visual Studio." Karen Payne | Sciencx - Friday August 22, 2025, https://www.scien.cx/2025/08/22/create-c-nested-files-in-visual-studio/
HARVARD
Karen Payne | Sciencx Friday August 22, 2025 » Create C# nested files in Visual Studio., viewed ,<https://www.scien.cx/2025/08/22/create-c-nested-files-in-visual-studio/>
VANCOUVER
Karen Payne | Sciencx - » Create C# nested files in Visual Studio. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/22/create-c-nested-files-in-visual-studio/
CHICAGO
" » Create C# nested files in Visual Studio." Karen Payne | Sciencx - Accessed . https://www.scien.cx/2025/08/22/create-c-nested-files-in-visual-studio/
IEEE
" » Create C# nested files in Visual Studio." Karen Payne | Sciencx [Online]. Available: https://www.scien.cx/2025/08/22/create-c-nested-files-in-visual-studio/. [Accessed: ]
rf:citation
» Create C# nested files in Visual Studio | Karen Payne | Sciencx | https://www.scien.cx/2025/08/22/create-c-nested-files-in-visual-studio/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.