如何从TFS构建过程向PowerShell脚本传递参数?

8

我创建了一个小的PowerShell脚本来更改我的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)

我已将它添加到我的构建过程中。如何将构建变量传递到脚本中?
(我使用新的基于脚本的构建过程,因此只有一个内置的“参数”字段可用于参数)

修改 web.config 应该在发布过程中进行,而不是构建过程中进行。 - Daniel Mann
我使用构建过程将我的网站放到每个检入时的两个测试服务器上。如何在没有构建过程的情况下完成这个任务? - Kiss László
1个回答

7
您可以将所有参数放在一个单独的行中,例如Arguments文件:
-webConfigPath "c:\web.config" -connectionStringName "My connection string"

谢谢!我还有一个问题。如何传递构建过程中的变量?例如BuildConfiguration和我的自定义属性。 - Kiss László
使用源代码中的$Env:BUILD_BUILDNUMBER语法。哦,我真傻。 - Kiss László

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接