并且web.config转换不起作用....将无法正常工作grrrrr

时间:2014-10-04 03:40:26

标签: asp.net web-config-transform

我正在使用Visual Studio 2010.我有这个web.config

<?xml version="1.0"?>
<configuration>
  <system.web>      
      <compilation debug="true" targetFramework="4.0" />
      <authorization>
        <allow roles="domain\allow" />
        <deny users="*" />
      </authorization>      
    </system.web>
</configuration>

现在我已经解决了 - &gt; Configuration Manager并添加了一个名为&#34; Production&#34;

的新配置

现在我来了,右键单击我的web.config并单击&#34;添加配置转换&#34;

现在我可以看到一个名为web.Production.config的文件

我去把它添加到我的文件

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="FooDB" connectionString="Data Source=FooServer;Initial Catalog=FooDB;Integrated Security=True;" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

现在,当我构建并发布项目时,我看到了一条错误消息

Web.Production.config(17,4): Warning : No element in the source document matches '/configuration/connectionStrings'

2 个答案:

答案 0 :(得分:1)

当我尝试使用发布配置文件时,我遇到了同样的问题。这对我有用:

调用您的其他Web.config文件Web.Debug.config(测试)和Web.Release.config(生产),然后在发布期间将Debug配置关联到测试发布配置文件和生产发布配置文件的Release配置。

编辑:

尝试将xdt:Transform更改为Insert并删除xdt:Locator属性。

答案 1 :(得分:1)

connectionStrings移至主web.config。生产配置中应该出现的唯一内容是转换。

相关问题