If you need a working way to use development settings like .net core does with appsettings.json and appsettings.Development.json, you can follow this steps.
-
Install nuget package MSBuild.Microsoft.VisualStudio.Web.targets dependency on your executable project to transform config files.
-
Edit your .csproj file on executable project.
-
Add your App.Debug.config as below (in case of being a web application, Web.config & Web.Debug.config). This adds a nice tree list on VS of these two files:
<ItemGroup>
<None Include="App.config" />
<None Include="App.Debug.config">
<DependentUpon>App.config</DependentUpon>
</None>
...
</ItemGroup>
- Put this before first
<ItemGroup>
ONLY if your project use an App.config instead of Web.config (ex.: console applications):
<PropertyGroup>
<ProjectConfigFileName>App.config</ProjectConfigFileName>
</PropertyGroup>
- Put this before closing
</Project>
. This adds a task to transform the the App.config/Web.config to App.{CurrentConfig}.config if exists:
<Target Name="AfterBuild" Condition="Exists('./$(ProjectConfigTransformFileName)')">
<TransformXml Source="@(AppConfigWithTargetPath)" Transform="$(ProjectConfigTransformFileName)" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" />
</Target>
- Use App.Debug.config/Web.Debug.config:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<!-- overwrite connection string -->
<add name="DbConnectionString" value="..." xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>
<appSettings>
<!-- overwrite setting -->
<add key="Environment" value="development" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<!-- insert new setting -->
<add key="LogLevel" value="0" xdt:Transform="Insert" />
</appSettings>
</configuration>