Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters to PowerShell script from TFS build process?

I created a little PowerShell script to change connection string in my web.config.

param([string]$webConfigPath, [string]$connectionStringName, [string]$connectionStringValue)

# get the full path of the web config file
$webConfigFile = [IO.Path]::Combine($webConfigPath, 'Web.config')
# load the XML
$webConfig = [xml](cat $webConfigFile)

#change the appropriate config
$webConfig.configuration.connectionStrings.add | foreach {
    if($_.name -eq  $connectionStringName){
        $_.connectionString = $connectionStringValue
    }
}

#save the file
$webConfig.Save($webConfigFile)

I added it to my build process. How to pass the build's variables to the script?

(I use the new script based build process, so I only have a builtin "Arguments" field for the parameter)

like image 579
Kiss László Avatar asked Mar 21 '16 21:03

Kiss László


1 Answers

You can put all parameters in a single line into Arguments files like this:

-webConfigPath "c:\web.config" -connectionStringName "My connection string"
like image 165
Thomas Bennet Avatar answered Oct 11 '22 01:10

Thomas Bennet