Last active
August 29, 2015 14:00
-
-
Save zachbonham/11303600 to your computer and use it in GitHub Desktop.
More fun with PowerShell string expansion for .NET app/web.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Usage: | |
ApplyConfig "app.config" "DEV" | |
$configFile - the app/web.config we are 'transforming'. | |
$environment - the environment context we are transforming for. Maybe snarf this from <appSettings><add key="Environment" value="some value"/>? | |
#> | |
param($configFile, $environment="LOCAL") | |
$workingDirectory = Split-Path $MyInvocation.MyCommand.Path | |
# dot sourcing our variable declarations | |
# | |
. .\$($environment).tokens.ps1 | |
$configFilePath = join-path $workingDirectory $configFile -resolve | |
$content = [IO.File]::ReadAllText($configFilePath) | |
#content contains all of our configuration, with variable expressions | |
#calling ExpandString will replace those expressions with their values | |
# | |
$expandedConfig = $ExecutionContext.InvokeCommand.ExpandString($content) | |
# uncomment to see values | |
# $expandedConfig | |
#set-content with $expandedConfig in output folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$MyDbConnection="my DEV connection string" | |
$HostMachineName = "DEV001" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$MyDbConnection="my local connection string" | |
$HostMachineName = [environment]::machinename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment