web config transform - Powershell Script: prompt a file (by mask) and use that file in a command line -


disclaimer: don't know enough ps accomplish in reasonable amount of time, yes, asking else dirty job.

i want able run web.config transformation without opening command line.

i have following files in folder:

web.config - actual web config web.qa.config - web config transformation qa env web.production.config - web config transformation production env transform.ps1 - powershell script want use run transformation 

here want: ps file shall enumerate current directory using .*\.(?<env>.*?)\.config , let me choose <env> interested in generate web.config for. in example presented 2 options: "qa", "production".

after (user) select environment (let's "qa", selected environment stored $env, , corresponding filename stored $transformation) script shall following:

  1. backup original web.config web.config.bak
  2. execute following command:

.

echo applying $transformation... [ctt][1].exe source:web.config transformation:$transformation destination:web.config preservewhitespaces verbose echo done. 

ctt.exe tool based on xdt runs web.config transformation command line.

okay, looks simple enough, i'll dirty job you. ;)

save following transform.ps1:

    $environments = @()f     gci | %{if ($_ -match '.*\.(?<env>.*?)\.config') {$environments += $matches.env}}     write-host "`nenvironments:"     ($i = 0; $i -lt $environments.length; $i++) {write-host "[$($i + 1)] $($environments[$i])"}     write-host     {         $selection = [int](read-host "please select environment")         if ($selection -gt 0 -and $selection -le $environments.length) {             $continue = $true         } else {             write-host "invalid selection. please enter number of environment select list."         }     } until ($continue)     $transformation = "web.$($environments[$selection - 1]).config"     if (test-path .\web.config) {         cpi .\web.config .\web.config.bak     } else {         write-warning "web.config not exist. no backup created."     }     if ($?) {         write-host "`napplying $transformation..."         [ctt][1].exe source:web.config transformation:$transformation destination:web.config preservewhitespaces verbose         write-host "done.`n"     } else {         write-error "failed create backup of web.config. transformation aborted."     } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -