Various configuration files for development and production in an ASP.NET application

In the project I'm working on, we have a web application with three configuration files; Web.Config Web.Config.TestServer Web.Config.LiveServer

When we go to the test server, Web.Config is renamed to Web.Config.Development and Web.Config.TestServer is renamed to Web.Config, making this configuration active for the application.

This is quite cumbersome, keeping three very similar configuration files up to date, and this system is used in many applications that are part of this project; not just the website.

The differences in configuration are most often local directories or paths, URLs, IP addresses, port numbers, and email addresses.

I am looking for a better way.

+3
source share
3 answers

Although your approach seems tedious, I believe this is the best approach.

I used all my configurations in a single web.config file and just commented on the Production section.

Soon after, I had to run a “hybrid” test, where my search data came from a production server, but new data was inserted into the test database. At this point, I had to start piecewise-mechanical processing of parts of the configuration block to comment / uncomment, and this became a nightmare.

, , .NET, , web.config. .test .prod .

- , , .

, ( ) , , .

+3

db , , , , , , web.config, (dev, test, prod).

dbs , , .

+2

Config Transformation, .

http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx

web. {build configuration}.config. , , .

web.staging.configss

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
     <connectionStrings> 
        <add name="personalDB" 
          connectionString="Server=StagingBox; Database=personal; User Id=admin; password=StagingPersonalPassword" 
          providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)" /> 
        <add name="professionalDB" 
         connectionString="Server=StagingBox; Database=professional; User Id=professional; password=StagingProfessionalPassword" 
         providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)"/> 
       </connectionStrings> 
</configuration>

Then you do the conversion, calling MSBuild {project file} /t:TransformWebConfig /p:Configuration=Staging

+1
source

Source: https://habr.com/ru/post/1703152/


All Articles