如何使用 xmlmassupdate (msbuild) 将新部分添加到 web.config

发布于 2024-11-19 13:23:06 字数 3864 浏览 6 评论 0原文

作为新版本安装的一部分,我们有 web.config.delta 文件,可以根据需要调整现有的 web.config 文件。现在我知道如何添加/更新/删除 AppSetting 键(因为我在这方面找到的所有帖子都是关于此的),但我不知道该怎么做是添加新的部分元素,添加新的部分组。

IE。这是我的 web.config 中的所有新内容。我需要更改什么才能将其应用为“增量”?

<?xml version="1.0"?>
<configuration xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">

<configSections>
<section xmu:key="name" name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section xmu:key="name" name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />

<sectionGroup name="authorization" type="Company.Security.Configuration.AuthorizationSectionGroup, Company.Library">
      <section name="rowLevelSecurity" type="Company.Security.Configuration.RowLevelAuthorizationSection, Company.Library"/>
      <section name="typeBasedSecurity" type="Company.Security.Configuration.TypeAuthorizationSection, Company.Library"/>
    </sectionGroup>

</configSections>

<enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
    <sources>
      <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      <add name="Security-FileBasedConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        filePath="Config/Enterprise-Security.config" />
    </sources>
    <redirectSections>
      <add sourceName="Security-FileBasedConfigurationSource" name="securityConfiguration" />
    </redirectSections>
  </enterpriseLibrary.ConfigurationSource>

  <authorization>
    <rowLevelSecurity defaultProvider="SqlMembershipRowLevelSecurity">
      <providers>
        <add name="SqlMembershipRowLevelSecurity" type="Company.Security.DataAuthorization.SqlMembershipRowLevelSecurityProvider, Company.Library"  applicationName="app1" connectionStringName="SecurityConnection"/>
      </providers>
    </rowLevelSecurity>
    <typeBasedSecurity defaultProvider="SqlInPlaceTypeBasedSecurity">
      <providers>
        <add name="SqlInPlaceTypeBasedSecurity" type="Company.Security.Providers.SqlEntityTypeFunctionTypeSecurityProvider, Company.Common"  applicationName="app1" connectionStringName="SecurityConnection"/>
      </providers>
    </typeBasedSecurity>
  </authorization>

</configuration>

我似乎找不到任何关于这些东西的简单信息 - 但也许我在谷歌上搜索了错误的术语。

我是否只需要替换添加位,例如:

<add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

<add xmu:key="name" name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" xmu:action="add" />

或者我是否必须对部分、部分组和 enterpriseLibrary.ConfigurationSource 元素执行相同的操作?

谢谢!

As part of our installation of new versions we have web.config.delta files that adjust the existing web.config files as appropriate. Now I know how to add/update/remove AppSetting keys (as all the posts I've found on this have been about that) but what I don't know how to do is add new section elements, add new sectiongroup.

ie. this is all the new stuff in my web.config. What do I need to change to make it get applied as a "delta"?

<?xml version="1.0"?>
<configuration xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">

<configSections>
<section xmu:key="name" name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section xmu:key="name" name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />

<sectionGroup name="authorization" type="Company.Security.Configuration.AuthorizationSectionGroup, Company.Library">
      <section name="rowLevelSecurity" type="Company.Security.Configuration.RowLevelAuthorizationSection, Company.Library"/>
      <section name="typeBasedSecurity" type="Company.Security.Configuration.TypeAuthorizationSection, Company.Library"/>
    </sectionGroup>

</configSections>

<enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
    <sources>
      <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      <add name="Security-FileBasedConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        filePath="Config/Enterprise-Security.config" />
    </sources>
    <redirectSections>
      <add sourceName="Security-FileBasedConfigurationSource" name="securityConfiguration" />
    </redirectSections>
  </enterpriseLibrary.ConfigurationSource>

  <authorization>
    <rowLevelSecurity defaultProvider="SqlMembershipRowLevelSecurity">
      <providers>
        <add name="SqlMembershipRowLevelSecurity" type="Company.Security.DataAuthorization.SqlMembershipRowLevelSecurityProvider, Company.Library"  applicationName="app1" connectionStringName="SecurityConnection"/>
      </providers>
    </rowLevelSecurity>
    <typeBasedSecurity defaultProvider="SqlInPlaceTypeBasedSecurity">
      <providers>
        <add name="SqlInPlaceTypeBasedSecurity" type="Company.Security.Providers.SqlEntityTypeFunctionTypeSecurityProvider, Company.Common"  applicationName="app1" connectionStringName="SecurityConnection"/>
      </providers>
    </typeBasedSecurity>
  </authorization>

</configuration>

I can't seem to find any simple information on this stuff - but maybe I'm googling with the wrong terminology.

Do I just need to replace the add bits like:

<add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

<add xmu:key="name" name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" xmu:action="add" />

or do I have to do the same things for the section, sectiongroup and enterpriseLibrary.ConfigurationSource elements??

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白鸥掠海 2024-11-26 13:23:06

值得庆幸的是,我发现了一个正在进行合并的单元测试,这样我就可以在内存中检查合并后的 XML。因此,通过反复试验发现我需要以下内容:

<?xml version="1.0"?>
<configuration xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate" xmlns:un="http://schemas.microsoft.com/practices/2010/unity">

  <configSections>
    <section xmu:key="name" name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" xmu:action="add" />
    <section xmu:key="name" name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" xmu:action="add"/>

    <sectionGroup xmu:key="name" name="authorization" type="Company.Security.Configuration.AuthorizationSectionGroup, Company.Library" xmu:action="add">
      <section xmu:key="name" name="rowLevelSecurity" type="Company.Security.Configuration.RowLevelAuthorizationSection, Company.Library" xmu:action="add"/>
      <section xmu:key="name" name="typeBasedSecurity" type="Company.Security.Configuration.TypeAuthorizationSection, Company.Library" xmu:action="add"/>
    </sectionGroup>

  </configSections>

  <enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
    <sources>
      <add xmu:key="name" name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" xmu:action="add" />
      <add xmu:key="name" name="Security-FileBasedConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        filePath="Config/Enterprise-Security.config" xmu:action="add" />
    </sources>
    <redirectSections>
      <add xmu:key="name" sourceName="Security-FileBasedConfigurationSource" name="securityConfiguration" xmu:action="add" />
    </redirectSections>
  </enterpriseLibrary.ConfigurationSource>

  <authorization>
    <rowLevelSecurity defaultProvider="SqlMembershipRowLevelSecurity">
      <providers>
        <add xmu:key="name" name="SqlMembershipRowLevelSecurity" type="Company.Security.DataAuthorization.SqlMembershipRowLevelSecurityProvider, Company.Library"  applicationName="app1" connectionStringName="SecurityConnection" xmu:action="add" />
      </providers>
    </rowLevelSecurity>
    <typeBasedSecurity defaultProvider="SqlInPlaceTypeBasedSecurity">
      <providers>
        <add xmu:key="name" name="SqlInPlaceTypeBasedSecurity" type="InPlace.Security.Providers.SqlEntityTypeFunctionTypeSecurityProvider, InPlace.Common"  applicationName="app1" connectionStringName="SecurityConnection" xmu:action="add"/>
      </providers>
    </typeBasedSecurity>
  </authorization>

  <un:unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <un:container>
      <un:register xmu:key="type" type="Company.Interface.Logging.ILoggingProvider, Company.Library" mapTo="Company.NHibernate.LoggingProvider, Company.NHibernate" xmu:action="add">
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.ITaskAuthorizationManager, Company.Library" mapTo="Company.EnterpriseLibrary.Security.TaskAuthorizationManager, Company.EnterpriseLibrary" xmu:action="add" >
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.ITypeAuthorizationManager, Company.Library" mapTo="Company.EnterpriseLibrary.Security.TypeAuthorizationManager, Company.EnterpriseLibrary" xmu:action="add" >
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.IPropertyAuthorizationManager, Company.Library" mapTo="Company.EnterpriseLibrary.Security.PropertyAuthorizationManager, Company.EnterpriseLibrary" xmu:action="add" >
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.IRoleAuthorizationManager, Company.Library" mapTo="Company.Web.Security.RoleAuthorizationManager, Company.Library" xmu:action="add">
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.IRowLevelAuthorizationManager, Company.Library" mapTo="Company.Web.Security.RowLevelAuthorizationManager, Company.Library" xmu:action="add">
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" name="TypeSecurityProvider" type="Company.Security.TypeBasedAuthorization.TypeSecurityProvider, Company.Library" mapTo="Company.Security.Providers.SqlEntityTypeFunctionTypeSecurityProvider, Company.Common" xmu:action="add"/>
    </un:container>
  </un:unity>

</configuration>

So thankfully I found a unit test that was doing a merge so in memory I could check the XML after the merge. So using trial and error found I needed the below:

<?xml version="1.0"?>
<configuration xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate" xmlns:un="http://schemas.microsoft.com/practices/2010/unity">

  <configSections>
    <section xmu:key="name" name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" xmu:action="add" />
    <section xmu:key="name" name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" xmu:action="add"/>

    <sectionGroup xmu:key="name" name="authorization" type="Company.Security.Configuration.AuthorizationSectionGroup, Company.Library" xmu:action="add">
      <section xmu:key="name" name="rowLevelSecurity" type="Company.Security.Configuration.RowLevelAuthorizationSection, Company.Library" xmu:action="add"/>
      <section xmu:key="name" name="typeBasedSecurity" type="Company.Security.Configuration.TypeAuthorizationSection, Company.Library" xmu:action="add"/>
    </sectionGroup>

  </configSections>

  <enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
    <sources>
      <add xmu:key="name" name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" xmu:action="add" />
      <add xmu:key="name" name="Security-FileBasedConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        filePath="Config/Enterprise-Security.config" xmu:action="add" />
    </sources>
    <redirectSections>
      <add xmu:key="name" sourceName="Security-FileBasedConfigurationSource" name="securityConfiguration" xmu:action="add" />
    </redirectSections>
  </enterpriseLibrary.ConfigurationSource>

  <authorization>
    <rowLevelSecurity defaultProvider="SqlMembershipRowLevelSecurity">
      <providers>
        <add xmu:key="name" name="SqlMembershipRowLevelSecurity" type="Company.Security.DataAuthorization.SqlMembershipRowLevelSecurityProvider, Company.Library"  applicationName="app1" connectionStringName="SecurityConnection" xmu:action="add" />
      </providers>
    </rowLevelSecurity>
    <typeBasedSecurity defaultProvider="SqlInPlaceTypeBasedSecurity">
      <providers>
        <add xmu:key="name" name="SqlInPlaceTypeBasedSecurity" type="InPlace.Security.Providers.SqlEntityTypeFunctionTypeSecurityProvider, InPlace.Common"  applicationName="app1" connectionStringName="SecurityConnection" xmu:action="add"/>
      </providers>
    </typeBasedSecurity>
  </authorization>

  <un:unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <un:container>
      <un:register xmu:key="type" type="Company.Interface.Logging.ILoggingProvider, Company.Library" mapTo="Company.NHibernate.LoggingProvider, Company.NHibernate" xmu:action="add">
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.ITaskAuthorizationManager, Company.Library" mapTo="Company.EnterpriseLibrary.Security.TaskAuthorizationManager, Company.EnterpriseLibrary" xmu:action="add" >
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.ITypeAuthorizationManager, Company.Library" mapTo="Company.EnterpriseLibrary.Security.TypeAuthorizationManager, Company.EnterpriseLibrary" xmu:action="add" >
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.IPropertyAuthorizationManager, Company.Library" mapTo="Company.EnterpriseLibrary.Security.PropertyAuthorizationManager, Company.EnterpriseLibrary" xmu:action="add" >
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.IRoleAuthorizationManager, Company.Library" mapTo="Company.Web.Security.RoleAuthorizationManager, Company.Library" xmu:action="add">
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" type="Company.Interface.Security.IRowLevelAuthorizationManager, Company.Library" mapTo="Company.Web.Security.RowLevelAuthorizationManager, Company.Library" xmu:action="add">
        <un:lifetime type="singleton" />
      </un:register>
      <un:register xmu:key="type" name="TypeSecurityProvider" type="Company.Security.TypeBasedAuthorization.TypeSecurityProvider, Company.Library" mapTo="Company.Security.Providers.SqlEntityTypeFunctionTypeSecurityProvider, Company.Common" xmu:action="add"/>
    </un:container>
  </un:unity>

</configuration>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文