VS2010清理Web.configs - 不更新

时间:2010-04-14 01:03:46

标签: visual-studio visual-studio-2010 web-config

我在VS2010上搞乱了MVC 2.0,并且在使用干净的Web配置功能时遇到了问题。

基本上在Web.debug.config我有

<connectionStrings xdt:Transform="Replace">
  <add name="ApplicationServices" 
    connectionString="Server=localhost;Database=SITE_DB;User ID=dbuser;Password=P@ssw0rd;Trusted_Connection=False;" />
</connectionStrings>

and in my `Web.config` I have

      <connectionStrings>
        <add name="ApplicationServices"
             connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
             providerName="System.Data.SqlClient" />
      </connectionStrings>

当我在调试模式下运行网站时,我希望xdt:Transform =“Replace”会用Web.debug.config中的内容替换整个connectionStrings部分。

我错了吗?或者我做其他事情是不正确的。没有多少信息张贴在这周围,我想我会问你们。

3 个答案:

答案 0 :(得分:11)

仅在以某种方式发布或部署应用程序时才会发生.config转换。如果您只是调试,则不会发生转换。

这听起来很疯狂,但它直接来自MS代表: http://forums.asp.net/p/1532038/3711423.aspx

答案 1 :(得分:1)

您可以启用此行为,但您需要创建一个“模板”文件,以将预转换状态存储在未命名为Web.config的文件中,否则您只需使用转换后的更改覆盖模板。您还需要向项目文件添加转换任务,以便在调试时执行。

<PropertyGroup>  
    <BuildDependsOn>  
        CustomWebConfigTransform;  
        $(BuildDependsOn);  
    </BuildDependsOn>  
</PropertyGroup>  
<Target Name="CustomWebConfigTransform">  
    <TransformXml source="Web.template.config"  
        transform="Web.$(Configuration).config"  
        destination="Web.config" />
</Target>  

上面的示例假设您有一个名为Web.template.config的模板web.config文件,并将在您运行项目时应用转换并创建Web.config文件。

参考:http://www.kongsli.net/nblog/2012/01/13/enabling-web-transforms-when-debugging-asp-net-apps/

答案 2 :(得分:0)

我认为你需要把xdt:Locator =“Match(name)”放在

<connectionStrings xdt:Transform="Replace" xdt:Locator="Match(name)">   
    <add name="ApplicationServices" 
      connectionString="Server=localhost;Database=SITE_DB;
      User ID=dbuser;Password=P@ssw0rd;Trusted_Connection=False;" 
     /> 
</connectionStrings>