使用Azure Powershell脚本在部署期间更改Web.config中的端点

时间:2016-06-13 12:06:26

标签: asp.net-mvc powershell azure web-config web-deployment

我最近创建了一个Powershell脚本,将我的Web应用程序(ASP.NET MVC)部署到Azure。它的工作方式应该如此,但我发现它可以通过在部署期间更改Web.config文件中的端点来改进脚本,即脚本会提示用户输入地址。 Web.config部分如下所示:

<system.serviceModel>
    <client>
      <endpoint address="http://localhost:10421/MyService" binding="binding" bindingConfiguration="foo" contract="bar" name="id" />
    </client>
</system.serviceModel>

我想用我的脚本更改端点地址。

1 个答案:

答案 0 :(得分:1)

使用Get-Content cmdlet加载配置文件,访问属性并进行更改,最后使用Set-Content cmdlet将其写回:

[xml]$content = (Get-Content 'your_file')
$content.configuration.'system.serviceModel'.client.endpoint.address = 'YourNewAdress'
$content | Set-Content 'your_file'

注意:我认为system.serviceModel位于configuration节点内。如果没有,请省略。