发布时在服务器上更新连接字符串

Connection string updated on server when publishing

我正在尝试在发布期间更新生产服务器上的连接字符串值。我正在尝试以下操作但没有结果:

<connectionStrings>
add name="DataConnect" connectionString="Server=Pepe;Database=Oyeti;Integrated Security=SSPI;" xdt:Transform="Replace" />

还添加了 xdt:Locator,但我认为这不是正确的方法:

<connectionStrings>
add name="DataConnect" connectionString="Server=Pepe;Database=Oyeti;Integrated Security=SSPI;" xdt:Transform="Replace" xdt:Locator="Match(name)" />

我在那里没有看到什么?

谢谢!

您可以将 xdt:Transform="SetAttributes" xdt:Locator="Match(name) 属性添加到转换文件 (Web.Release.config) 中的 connectionString 标记以转换主配置文件 (Web.config) 中的值。或者,您也可以在发布配置文件中指定连接字符串。

Although the default transform file contains an example that shows how to update a connection string, in most cases you do not need to set up connection string transformations, because you can specify connection strings in the publish profile. You'll do that in the deploy to IIS and deploy to production tutorials.

https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations