为什么我在发布时会出现"匹配定位器"的"无属性"名称错误?

Mik*_*lls 8 visual-studio-2010 web-config-transform

我对此非常困惑.在我开发和使用实时SQL Server时,我想在我的桌面上使用SQL Server.我正在使用Visual Studio 2010中的转换内容.

当我尝试发布我的项目时,我得到了"匹配定位器"的"无属性"名称.

我的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>
Run Code Online (Sandbox Code Playgroud)

我还在测试它,所以现在,我的Web.Release.config文件包含:

<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>
Run Code Online (Sandbox Code Playgroud)

我在网上看到的任何东西都让我更加困惑.有什么帮助让我起床和跑步?

Mar*_*llo 12

xdt:Locator="Match(name)表示系统将匹配使用名称标签替换的节点.如果您没有name属性,那么它将失败.您必须具有一些唯一属性才能使用此类转换.


Mik*_*lls 9

卫生署!问题出在该sessionState部分.它应该是:

<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>
Run Code Online (Sandbox Code Playgroud)


Nac*_*cho 5

在 Match(name) 中使用 "name" 用于典​​型的配置设置,如下所示。在这种情况下,关键是“名称”。

<add name="errorAddress" email="me@google.com" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
Run Code Online (Sandbox Code Playgroud)

如果您的设置中的键是其他东西,那就是您需要使用的:

<add token="UserToken" value="23jkl2klk2j3kja9d8f" xdt:Transform="SetAttributes" xdt:Locator="Match(token)"/>
Run Code Online (Sandbox Code Playgroud)