So I added .config files for my development, preproduction and production environment, but Visual Studio just added the files at the same level as the appsettings.config file:
Usually, Visual Studio groups the config files together to show a nested view of the files. But not this time. To fix this, I modified the .csproj file like this:
<ItemGroup>
<None Update="appsettings.development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DependentUpon>appsettings.json</DependentUpon>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.preproduction.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DependentUpon>appsettings.json</DependentUpon>
</None>
<None Update="appsettings.production.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DependentUpon>appsettings.json</DependentUpon>
</None>
</ItemGroup>
To get the files nested, I added the DependentUpon property, so my appsettings.development.json, appsettings.preproduction.json and appsettings.production.json is dependent upon the appsettings.json.
With this change, Visual Studio shows my .config files in a nested manner:
That’s it. Happy coding.
MORE TO READ:
- Tip: Visual Studio Custom File Nesting from Mitch
- File nesting in VS Code from dev.to