2010-04-14 77 views
8

我在VS2010上搞乱了MVC 2.0,并且遇到了干净的web配置功能工作的问题。VS2010清洁Web.configs - 不更新

基本上在我的Web.debug.config我有

<connectionStrings xdt:Transform="Replace"> 
    <add name="ApplicationServices" 
    connectionString="Server=localhost;Database=SITE_DB;User ID=dbuser;[email protected];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:转换=“替换”将取代什么是Web整个connectionStrings节.debug.config。

我假设错了吗?或者我在做别的不正确的事情。周围没有太多的信息,我想我会问你们。

回答

0

我认为你需要把XDT:定位器=“匹配(名称)”中

<connectionStrings xdt:Transform="Replace" xdt:Locator="Match(name)"> 
    <add name="ApplicationServices" 
     connectionString="Server=localhost;Database=SITE_DB; 
     User ID=dbuser;[email protected];Trusted_Connection=False;" 
    /> 
</connectionStrings> 
+0

如果他想在的ConnectionStrings元素取代寄托都发生了什么?现在,Match(名称)不起作用,对吧?因为它试图在connectionStrings _element_上寻找一个名为'name'的_attribute_ ..它不存在。 attrib存在于 _child_元素中.. (只是在想 - 大声点,这里...) – 2010-06-11 00:58:56

+0

Pure.Krome是正确的。您需要删除Locator变换或将两个变换移动到添加XNode而不是connectionStrings XNode。 – 2011-03-26 05:24:36

11

的变换的.config只发生在发布或部署以某种方式应用。如果你只是在调试,转换不会发生。

这听起来很疯狂,但它从一个MS代表的嘴是直: http://forums.asp.net/p/1532038/3711423.aspx

+1

今天这个疯狂的行为花了我相当一段时间:(谢谢指出解释! – Daan 2011-04-28 10:36:05

+1

如果Web.Debug.config从未被使用过,那么它有什么意义?它只是在混淆人们吗? – 2012-12-09 01:28:39

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/