Deployment mit Powershell – Schritt 3: Werte in der Web.Config über Variablen setzen.

by robert 8. May 2009 21:07

Beim Einrichten einer neuen Webseite geht es immer auch darum ein paar Konfigurationswerte anzupassen. In unserem konkreten Fall benötigen wir lediglich:

  • ApplicationPath
  • ConnectionString

Hier hilft der klassische Template Processor:

web-config template engine

Wobei “Deployment.ps1” die “Template-Engine” ist

   1: function CopyAndChangeWebConfig
   2: {
   3:     $webConfigTemplate = Get-Content -Path $path_sourceConfigTemplate -Encoding UTF8;
   4:     $webConfigTemplate = $webConfigTemplate -replace("#ApplicationPath#", $path_targetDeployment );
   5:     $webConfigTemplate = $webConfigTemplate -replace("#ConnectionString#", $Server );    
   6:     Set-Content -Path ($path_targetDeployment + "/web.config") -Encoding UTF8 -Value $webConfigTemplate;    
   7: }

Lesen, ersetzen, zurückschreiben und leicht zu erweitern.

:-)

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.