Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2010 特定于服务器的Web.config替换_Visual Studio 2010_Web Config - Fatal编程技术网

Visual studio 2010 特定于服务器的Web.config替换

Visual studio 2010 特定于服务器的Web.config替换,visual-studio-2010,web-config,Visual Studio 2010,Web Config,我目前正在使用VisualStudio2010。我想为我的“测试”配置设置一个不同的连接字符串。我已经尝试过使用配置转换来实现这一点,但它似乎不起作用 在myWeb.config中,我的连接字符串如下所示: <add name="MyDb" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DevelopmentDb;Integrated Security=SSPI; MultipleActiveResultSets=Tr

我目前正在使用VisualStudio2010。我想为我的“测试”配置设置一个不同的连接字符串。我已经尝试过使用配置转换来实现这一点,但它似乎不起作用

在myWeb.config中,我的连接字符串如下所示:

<add name="MyDb" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DevelopmentDb;Integrated Security=SSPI; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

我发现可以通过添加配置转换来替换Web.config中定义的连接字符串。我右键单击Web.config并单击“添加配置转换”。这创建了一个Web.TEST.config文件。然后我添加了一个连接字符串替换,但它似乎不起作用。它仍然使用Web.config中定义的连接字符串

Web.TEST.config的文件内容是:

<?xml version="1.0"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!--
    In the example below, the "SetAttributes" transform will change the value of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an atrribute "name" that has a value of "MyDB".
  -->

    <connectionStrings>
      <add name="MyDb" 
        connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TestDb;Integrated Security=SSPI; MultipleActiveResultSets=True" 
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
  <system.web>
    <!--
      In the example below, the "Replace" transform will replace the entire 
      <customErrors> section of your web.config file.
      Note that because there is only one customErrors section under the 
      <system.web> node, there is no need to use the "xdt:Locator" attribute.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>
    -->
  </system.web>
</configuration>


对我可能缺少的东西有什么想法吗?

在部署项目时应用转换,而不是在编译项目时

如果您使用的是IIS,则可以部署到已配置的web应用程序目录,这将导致应用转换