3

我的Web.Config轉換沒有被髮布 - 我認爲這個錯誤與我得到的這些警告有關。這些Visual Studio警告是什麼意思?

使用Visual Studio 2010,我正在玩我的Web.Config/Web.Config.Debug文件。

在我的.Debug文件中,我收到以下警告列出了許多次。

No element in the source document matches '/configuration' 

我認爲它會列出它爲每個部分存在於.Debug文件。

因此,以下示例Web.Config.Debug文件..將列出兩次。 (我猜,第一個是爲<connectionStrings>..</>,第二個是爲<system.webServer>...</.>

<?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" xdt:SupressWarnings="false"> 

    <connectionStrings> 
     <add name="Foo" connectionString="Server=foo;Database=Foo;uid=foo;password=foo" providerName="System.Data.SqlClient" 
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> 
    </connectionStrings> 

    <system.webServer> 
     <httpProtocol> 
      <customHeaders> 
       <clear /> 
       <add name="ETag" value="Dev_IIS" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" /> 
      </customHeaders> 
     </httpProtocol> 
    </system.webServer> 

</configuration> 

任何人的幫助,好嗎?

+0

我有同樣的問題:http://stackoverflow.com/questions/12593671/why-wont-my-web-config-transforms-work – 2012-09-26 03:21:17

回答

3

我發現this blog post這表明變壓器在xmlns =屬性上窒息。

我從此改變了我的Web.config文件:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> 
    <connectionStrings> 
    etc... 

這樣:

<configuration> 
    <connectionStrings> 
    etc... 

...你瞧,它的工作原理!

0

我創建了一個新的web應用程序項目(target .net 4.0),將Web.Release.config更改爲包含上面粘貼的內容。然後,我去了web.config並添加了以下內容:

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

然後我改變了配置來發布和發佈Web應用程序。已發佈應用程序包含在web.config中

<add name="ApplicationServices" 
    connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" 
    providerName="System.Data.SqlClient" /> 
<add name="Foo" 
    connectionString="Server=foo;Database=Foo;uid=foo;password=foo" 
    providerName="System.Data.SqlClient" /> <-------this got added 

所以我不知道問題出在哪裏,你的情況下。

+0

嘗試像我一樣創建一個新的項目,看看你是否能夠重現問題。 – 2010-06-23 03:50:51

+0

我有這個相同的問題(http://stackoverflow.com/questions/12593671/why-wont-my-web-config-transforms-work)。看起來Web.config中有些東西是轉換不喜歡的。我希望我知道... – 2012-09-26 03:24:03