I am trying to port an old dotnet framekwork 4.8 web application to dotnet core 3.1. This project is one of four project in my solution:
- dotnet core 3.1 (currently porting from dotnet framework 4.8 MVC project)
- dotnet framework 4.8 webforms project (migrating to .net core project)
- dotnet framework 4.8 class library (for shared code)
- dotnet framework 4.8 class library (for database)
The code in the existing class library (#3) uses the ConfigurationManager class to access the appsetting section of my app.config file. I can not change this code to take from my appsettings.json file because my dotnet framework webforms project also depends on the class library.
Is it possible to get the same transformation functionality that my old dotnet framework MVC project was doing for the app.config file? I would like to transform the app.config file when I publish and include the app.release.config contents.
Below I included an example of my app.config and app.release.config files. I removed all personal data so pleases let me know if you need clarification.
This is my app config file
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<!-- connection string here (used by the class libray and requires the file to be named app.config not web.config) -->
</connectionStrings>
<appSettings>
<add key="runasUserNoDomain" value="domianVal" />
<!-- Add More appsetting items here... -->
</appSettings>
</configuration>
This is my app.release.config file
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="website1" value="https://subdomain1.mydomain.com" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
<add key="website2" value="https://subdomain2.mydomain.com" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
</appSettings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>