3

我的 Web.Config 转换没有发布 - 我认为错误与我收到的这些警告有关。

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

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

No element in the source document matches '/configuration'

我认为它为文件中存在的每个部分列出了它。.Debug

因此,使用以下示例 Web.Config.Debug 文件 .. 将列出两次。(我猜,第一个是 for <connectionStrings>..</>,第二个是 for <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>

有人可以帮忙吗?

4

2 回答 2

3

我发现这篇博客文章表明变压器在 xmlns= 属性上阻塞。

我从这里更改了我的 Web.config 文件:

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

对此:

<configuration>
  <connectionStrings>
    etc...

...你瞧,它有效!

于 2012-09-26T03:51:36.337 回答
0

我创建了一个新的 Web 应用程序项目(针对 .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

所以我不确定你的问题出在哪里。

于 2010-06-23T02:20:29.737 回答