在发布管道期间覆盖 <connectionStrings>

Override <connectionStrings> during release pipeline

我的 Web.config 看起来像这样:

<connectionStrings configSource="secretConnectionStrings.config">
  </connectionStrings>

secretConnectionStrings.config 存储带密码的数据库连接字符串,不在源代码管理中。

我可以在 "Deploy Azure App Service" 任务中看到以下内容:

如何更新我的 VSTS 发布管道,以便 <connectionStrings> 部分替换为我提供的连接字符串(包括密码)?

我的存储库是 public,这就是为什么我不想在其中输入密码,只有受信任的人才能访问用于部署的 VSTS 帐户。

不完全是你要找的答案,但仍然是你问题的答案:看看 Azure App Service ConnectionStrings settings under Application Settings 做了什么:

For .NET apps, these connection strings are injected into your .NET configuration connectionStrings settings at runtime, overriding existing entries where the key equals the linked database name.

以巧妙的方式使用它可以使设置仅出现在应用服务上,而发布管道甚至不必知道它们。

当然,您也可以让发布管道更新应用服务上的设置。因为您可以使用 Azure App Service Deploy 任务执行 XML 转换,所以您可以删除外部文件引用。或将其全部删除。

另外,看看