Visual studio 2010 为什么我会得到一个“a”;无属性';名称';“匹配定位器”存在;发布时出错?

Visual studio 2010 为什么我会得到一个“a”;无属性';名称';“匹配定位器”存在;发布时出错?,visual-studio-2010,web-config-transform,Visual Studio 2010,Web Config Transform,我对此感到很困惑。我希望在开发时使用桌面上的SQL Server,在发布项目时使用live SQL Server。我正在VisualStudio2010中使用转换功能 当我试图发布我的项目时,我得到“匹配定位器不存在属性'name' 我的Web.config文件包含: <connectionStrings> <add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS;Integrated Secu

我对此感到很困惑。我希望在开发时使用桌面上的SQL Server,在发布项目时使用live SQL Server。我正在VisualStudio2010中使用转换功能

当我试图发布我的项目时,我得到“匹配定位器不存在属性'name'

我的Web.config文件包含:

<connectionStrings>
    <add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db" providerName="System.Data.SqlClient"/>
</connectionStrings>

<system.web>
    <sessionState mode="SQLServer" sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=eGov" timeout="20" allowCustomSqlDatabase="true" />
</system.web>
<connectionStrings>
    <add name="EFDbContext"
        connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db" 
            providerName="System.Data.SqlClient" 
            xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>

<system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <sessionState mode="SQLServer"
        sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=app"
        timeout="20" allowCustomSqlDatabase="true"
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</system.web>

我仍在测试它,因此目前,我的Web.Release.config文件包含:

<connectionStrings>
    <add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db" providerName="System.Data.SqlClient"/>
</connectionStrings>

<system.web>
    <sessionState mode="SQLServer" sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=eGov" timeout="20" allowCustomSqlDatabase="true" />
</system.web>
<connectionStrings>
    <add name="EFDbContext"
        connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db" 
            providerName="System.Data.SqlClient" 
            xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>

<system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <sessionState mode="SQLServer"
        sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=app"
        timeout="20" allowCustomSqlDatabase="true"
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</system.web>


我在网上看到的任何东西只会让我更加困惑。有什么能帮我站起来跑步的吗?

Doh!问题出在
会话状态
部分。应该是:

<system.web>
    <sessionState mode="SQLServer"
        sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=app"
        timeout="20" allowCustomSqlDatabase="true"
        xdt:Transform="SetAttributes" xdt:Locator="XPath(configuration/system.web/sessionState)" />
</system.web>

xdt:Locator=“Match(name)
表示系统将使用name标记匹配要替换的节点。如果没有name属性,则会失败。必须具有某些唯一属性才能使用此类型的转换。

在Match(name)中使用“name”用于以下典型配置设置。本例中的键为“name”


如果设置中的键是其他键,则需要使用:

<add token="UserToken" value="23jkl2klk2j3kja9d8f" xdt:Transform="SetAttributes" xdt:Locator="Match(token)"/>