【问题标题】:App.Config transformation not workingApp.Config 转换不起作用
【发布时间】:2016-03-26 13:53:18
【问题描述】:

我正在尝试在我的构建服务器上动态更改 app.config,我创建了一个名为 Build 的配置,并且我有这 4 个 .config 文件。

这是我的 app.config

<connectionStrings>
    <!--configSource="connectionStrings.config"-->
    <add name="TestContext" connectionString="Data Source=ServerDoesNotExist;Initial Catalog=TestDb; Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>

在我的 app.build.config 上

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionstrings xdt:transform="Replace">
      <add name="TestContext" connectionstring="Data Source=REALEXISTINGSERVER;Initial Catalog=TestDb; Integrated Security=true" providername="System.Data.SqlClient"/>
  </connectionstrings>
</configuration>

但是,当我创建构建定义并添加 configuration =Build 时,出现此错误

错误:System.Data.SqlClient.SqlException:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:命名管道提供者,错误:40 - 无法打开与 SQL Server 的连接)---> System.ComponentModel.Win32Exception:找不到网络路径

这意味着获取 app.config 文件而不是转换

【问题讨论】:

  • 您是否检查过该文件是否在您的本地机器上正确转换(即来自 Visual Studio)。转换文件上的构建操作可能是错误的

标签: c# xml tfs tfsbuild


【解决方案1】:

你可以使用 SetAttributes

<connectionStrings>
    <add name="TestContext" connectionString="Data Source=REALEXISTINGSERVER;Initial Catalog=TestDb; Integrated Security=true" providername="System.Data.SqlClient" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>

请参考

How do I use Web.Config transform on my connection strings?

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 2014-02-26
    • 1970-01-01
    • 2011-09-05
    • 2018-08-13
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多