标签: web-config-transform

什么是正确的xdt:Locator参数来转换此节点?

我的app.config文件中有以下内容.我正在使用Slow Cheetah并且只想替换replace configuration/entityFramework/defaultConnectionFactory/parameters /参数,以便它指向diff服务器.即价值数据源=某些服务器....

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="data source=.;Integrated Security=SSPI;Initial Catalog=SomeDb;MultipleActiveResultSets=true" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我在app.config.release中尝试了以下内容,但无济于事.

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters> …
Run Code Online (Sandbox Code Playgroud)

web-config-transform xdt-transform visual-studio-2012

25
推荐指数
1
解决办法
1万
查看次数

XDT转换:InsertBefore - 忽略定位器条件

我有一个web.config文件,我需要插入该<configSections />元素或操作该节点的子节点(如果它已经存在).
如果它已经存在,我不想再插入它(显然,因为它只允许存在一次).

通常,这不会是一个问题,但是:

如果此元素位于配置文件中,则它必须是元素的第一个子元素.

资料来源:MSDN.

所以,如果我使用xdt:Transform="InsertIfMissing"<configSections />元素将始终任何现有的子元素后插入(及总有一些),违反不必是第一个子元素的它上面的限制<configuration />

我试图通过以下方式完成这项工作:

 <configSections
    xdt:Transform="InsertBefore(/configuration/*[1])"
    xdt:Locator="Condition(not(.))" />
Run Code Online (Sandbox Code Playgroud)

如果<configSections />元素尚不存在,哪个工作完美.但是,我指定的条件似乎被忽略了.

事实上,我尝试了一些条件,如:

Condition(not(/configuration[configSections]))
Condition(/configuration[configSections] = false())
Condition(not(/configuration/configSections))
Condition(/configuration/configSections = false())
Run Code Online (Sandbox Code Playgroud)

最后,出于绝望,我试过:

Condition(true() = false()) 
Run Code Online (Sandbox Code Playgroud)

它仍然插入了<configSections />元素.

重要的是要注意我正在尝试将其包含在NuGet包中,因此我将无法使用自定义转换(如AppHarbor使用的那个).

有没有其他聪明的方法可以将我的元素放在正确的位置,只有它尚不存在?

要测试它,请使用AppHarbors配置转换测试器.用以下内容替换Web.config:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="initialSection" />
  </configSections>
</configuration>
Run Code Online (Sandbox Code Playgroud)

和Web.Debug.config具有以下内容:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <configSections
    xdt:Transform="InsertBefore(/configuration/*[1])"
    xdt:Locator="Condition(true() = false())" />

  <configSections>
    <section name="mySection" xdt:Transform="Insert" />
  </configSections>

</configuration>
Run Code Online (Sandbox Code Playgroud)

结果将显示两个<configSections /> …

web-config web-config-transform xdt-transform

23
推荐指数
1
解决办法
9703
查看次数

web.config转换 - 从connectionstring部分删除注释

我在web.config中存储了几个不同的连接字符串,用于开发和测试.除了一个之外的所有内容都已注释掉,因此我可以根据需要更改信息

当我发布时,我想用connection:替换connectionStrings节点中的所有内容(包括注释):

<add name="myDb" connectionString="Data Source={SERVER};Initial Catalog=ManEx;User Id={USER};Password={PASSWORD};" providerName="System.Data.SqlClient"  />
<!--<add name="myDb" connectionString="Data Source={SERVER};Initial Catalog=ManEx;Integrated Security=True" providerName="System.Data.SqlClient" />-->
Run Code Online (Sandbox Code Playgroud)

我知道如何用这个改变活动字符串:

<add name="myDb"
     connectionString="Data Source={SERVER};Initial Catalog=ManEx;User Id={USER};Password={PASSWORD};"
     providerName="System.Data.SqlClient"
     xdt:Transform="Add" 
     xdt:Locator="Match(name)"/>
Run Code Online (Sandbox Code Playgroud)

但我不知道如何清除我不想要的评论,并添加我想要的评论.

有任何想法吗?

c# asp.net connection-string visual-studio web-config-transform

22
推荐指数
1
解决办法
6371
查看次数

microsoft.identityModel上的Web配置转换 - 未声明'http://schemas.microsoft.com/XML-Document-Transform'属性

我有一个成功转换连接字符串的Web.Release.config.

当我添加一个microsoft.identityModel部分时,我得到一个警告说

未声明"http://schemas.microsoft.com/XML-Document-Transform"属性

并且变换在该部分不起作用.

为了让转换工作,我错过了什么?

在这里完成Web.Release.config

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <connectionStrings>    

    <add name="MYNAME"
         connectionString="metadata=res://*/Models.MYCOMPANY-Sales-Demo.csdl|res://*/Models.MYCOMPANY-Sales-Demo.ssdl|res://*/Models.MYCOMPANY-Sales-Demo.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=MYCOMPANYDemo;UID=MYCOMPANYDBUser;Password=********;multipleactiveresultsets=True;App=EntityFramework&quot;"         
         xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
  </connectionStrings>

  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>


  <microsoft.identityModel> 
    <service>
      <audienceUris>
        <add value="http://MYCOMPANY-sales-demo.cloudapp.net/" xdt:Transform="Replace"/>
      </audienceUris>
      <federatedAuthentication>
        <wsFederation realm="http://MYCOMPANY-sales-demo.cloudapp.net/" xdt:Transform="SetAttributes(realm)" />
      </federatedAuthentication>       
    </service>
  </microsoft.identityModel>

</configuration>
Run Code Online (Sandbox Code Playgroud)

web-config transform web-config-transform

17
推荐指数
2
解决办法
6409
查看次数

有没有办法使用转换"插入"新的部分到Web.Config?

在我的Web.Config中,我有以下内容

  <system.webServer>

    <modules>
       **some code**
    </modules>
    <handlers>
       **some code**    
    </handlers>

  </system.webServer>
Run Code Online (Sandbox Code Playgroud)

如何对其进行转换,以便将"安全性"的新子节点注入"system.webServer"?到目前为止,我尝试和搜索过的所有内容都失败了.

我想要的是如下所示:

  <system.webServer>

    <modules>
       **some code**
    </modules>
    <handlers>
       **some code**    
    </handlers>

    <security>
      <ipSecurity allowUnlisted="false" denyAction="NotFound">
        <add allowed="true" ipAddress="10.148.176.10" />
      </ipSecurity>
    </security>

  </system.webServer>
Run Code Online (Sandbox Code Playgroud)

asp.net xslt web-config-transform xdt-transform

17
推荐指数
1
解决办法
4946
查看次数

发布是不是在改变web.config?

我做了一个web.config(完整文件,它没有显示XML错误)

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <configSections>
      ...
      <location path="." inheritInChildApplications="false">
        <connectionStrings>
          <add name="ElmahLog" connectionString="data source=~/App_Data/Error.db" />
          <add name="database" connectionString="w" providerName="System.Data.EntityClient"/>
        </connectionStrings>
      </location>
  ...
Run Code Online (Sandbox Code Playgroud)

使用转换文件(web.Staging.config)

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="database"
      connectionString="c"
      providerName="System.Data.EntityClient"
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
  </connectionStrings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <customErrors defaultRedirect="error.aspx"
      mode="RemoteOnly" xdt:Transform="Replace">
    </customErrors>
  </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我在Staging模式下发布(右键单击网站>发布>方法:文件系统...)

------ Build started: Project: Drawing, Configuration: Staging Any CPU ------
  Drawing -> D:\Project\bin\Staging\Drawing.dll
------ Build started: Project: MySystem, Configuration: Staging Any CPU ------ …
Run Code Online (Sandbox Code Playgroud)

asp.net deployment web-config .net-4.0 web-config-transform

15
推荐指数
3
解决办法
2万
查看次数

如何重命名web.config转换

我正在使用Visual Studio 2015中的ASP.net MVC 5解决方案.我有以下内容 web.config

web配置转换

我该如何重命名

  • Web.Integration.config
  • Web.Staging.config
  • Web.Production.config

当我右键单击那些时,我没有得到重命名选项!

visual-studio-2005 rename web-config-transform asp.net-mvc-5

14
推荐指数
2
解决办法
4235
查看次数

Web.Config自定义配置部分的转换

有没有人知道如何获取web.config转换来替换自定义配置部分.我已将msbuild设置为详细模式,并且转换只是忽略了带有替换变换的自定义部分的存在.

asp.net msbuild web-config msdeploy web-config-transform

13
推荐指数
1
解决办法
4470
查看次数

在针对不同环境执行web.config转换时出错

我试图将我的应用程序部署到不同的环境然后我开始遵循以下方法: 使用Visual Studio或Visual Web Developer将ASP.NET Web应用程序部署到托管提供程序:Web.Config文件转换 - 3 of 12

在我点击预览变换之前是完美的,我收到了这个错误:

Microsoft Visual Studio

无法加载文件或程序集"Microsoft.Web.XmlTransform,Version = 1.2.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"或其依赖项之一.该系统找不到指定的文件.

(我只创建了一个转换Web.DebugQA.config,当然还有默认的转换,调试和发布)

我的Web.DebugQA.config看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="MyDB" 
      connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>
  <system.web>
  </system.web>
  <appSettings>
    <add key="EnvironmentName" value="QADev" xdt:Transform="SetAttributes(value)"
      xdt:Locator="Match(key)" />
  </appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

但后来我安装了这个插件:

SlowCheetah - XML转换

我解决了我的预览转换错误,但是当我尝试使用QADev转换发布时,我遇到了这个错误:

"ImportParametersFile"任务意外失败.

System.IO.FileNotFoundException:无法加载文件或程序集"Microsoft.Web.XmlTransform,Version = 1.2.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"或其依赖项之一.该系统找不到指定的文件.文件名:'Microsoft.Web.XmlTransform,Version = 1.2.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'
,Microsoft.Web.Publishing.Tasks.ImportParametersFile.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build .BackEnd.ITaskExecutionHost.Execute()
在Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask> d__20.MoveNext() …

web-config-transform visual-studio-2012

11
推荐指数
2
解决办法
8481
查看次数

在发布/部署期间将DateTime.Now插入Web.Config

我希望在Web.Config中部署/发布应用程序的日期.

有没有办法通过web.config转换实现这一目标?

随着xdt:Transform="Replace"我可以替换预定值的任一节点,但有使用一些自定义的函数来计算值(如路DateTime.Now)?

asp.net web-config web-config-transform asp.net-mvc-3

10
推荐指数
1
解决办法
1581
查看次数