Update web.config based on another server using asp.net

I am looking for a simple and elegant way to change my appsettingsweb.config based on a different environment, and I have (dev / qa / test / stage / prod), and I manually change appsettingsits very tedious and laborious time, and I have dozens settings ... What is the best approach for this curious situation? I know one solution using Environment variables, but want to hear best practice?

+3
source share
8 answers

I prefer to use external sections of web.config, for example:

<appSettings configSource="appsettings.config" />

then appsettings.config looks like this:

<appSettings>
   <add key ...>
</appSettings>

, , web.config . - , system.net( ) ..

, VS2010 , . , VS , .

0
+2

:

  • , .
  • . , .
  • accessor, , .

, .

+1

VS2010 (NET tools version 4), - , .. , asp.net. tada, , . , . 3.5 .NET MSBuild 4, VS2010. , .

+1

, Web.config Visual Studio 2010, .

VS2010 , , . NANT script . , Web.config, .

http://blog.nathan-taylor.net/2009/10/webconfig-build-manager.html

+1

VS2010 ours web.prod.config, web.qa.config .. , .

VS2008 , , , . web.config dev, TFS .

+1

Nant script .

Nant web.config app.config , . QA.

0

, , .

, appsettings.config.debug, appsettings.config.deploy, web.config.debug, web.config.deploy.

script, , , , . , FC.

pre-build:

"$(ProjectDir)copyifnewer.bat" "$(ProjectDir)web.config.$(ConfigurationName)" "$(ProjectDir)web.config"

"$(ProjectDir)copyifnewer.bat" "$(ProjectDir)appsettings.config.$(ConfigurationName)" "$(ProjectDir)appsettings.config"

copyifnewer.bat:

echo Config Maintenance
echo Today date of %date:~-4,4%\%date:~-10,2%\%date:~-7,2%
rem echo Comparing two files: %1 with %2
echo .
if not exist %1 goto File1NotFound
if not exist %2 goto File2NotFound

fc %1 %2 
if %ERRORLEVEL%==0 GOTO NoCopy

echo These files are NOT the same.  Copying %1 over %2
copy %1 %2 /y & goto END

:NoCopy
echo These files are the same.  Nothing copied.
goto END

:File1NotFound
echo %1 not found.
goto END

:File2NotFound
copy %1 %2 /y
goto END

:END
echo Done.
echo .

. , -.

,

0

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


All Articles