2010-04-14 42 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/