Quantcast
Channel: Brian Pedersen's Sitecore and .NET Blog
Viewing all articles
Browse latest Browse all 285

Nesting appsettings.config files in Visual Studio

$
0
0

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:

Config files shown on the same level
Visual Studio showing config files on the same level

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:

.config files shown in a nested manner
.config files shown in a group

That’s it. Happy coding.

MORE TO READ:


Viewing all articles
Browse latest Browse all 285

Trending Articles