如何使用PowerShell更改Web.Config文件的值?

时间:2018-02-09 05:46:37

标签: powershell web-config azure-pipelines-release-pipeline

我正在开发PowerShell。在那,我试图在PowerShell的帮助下改变现有配置文件值的值,并且它运行良好。 但是我遇到了一个新的任务,如下所示,在转换PowerShell中的值以覆盖我的配置文件。对于此任务,我提到了link

如果有这样的代码:

   <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="service.tasks" type="HRNetTaskService.TaskConfigurationSection, TaskService" />

  </configSections>
  <connectionStrings>
    <add name="Production" connectionString="" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="RestServiceUrl" value="XXXXXXXXXXX" />   
  </appSettings>

  <service.tasks>
    <tasks>
      <!-- App.config specified tasks are always recurring starting from whenever The Service first schedules it -->

      <task name="ExpireRequirements" taskName="ExpireRequirements" recurrenceFactor="1" recurrenceType="Days" executeTime="01:00">
        <parameters>
          <param key="entityID">00000000-0000-0000-0000-000000000E01</param>
        </parameters>
      </task>
      <task name="RequestExpiredRequirementsTask" taskName="RequestExpiredRequirementsTask" recurrenceFactor="1" recurrenceType="Days" executeTime="01:00">
        <parameters>
          <param key="entityID">00000000-0000-0000-0000-000000000E01</param>
          <param key="CopyBatchSize">50</param>
        </parameters>
      </task>
      <task name="UpdateRequirementChecksEffectiveDateTask" taskName="UpdateRequirementChecksEffectiveDateTask" recurrenceFactor="1" recurrenceType="Days" executeTime="01:00">
        <parameters>
          <param key="entityID">00000000-0000-0000-0000-000000000E01</param>
        </parameters>
      </task>     
      <task name="PeoplenetMatchAssignmentRefresh" taskName="PeoplenetMatchAssignmentRefresh">
        <parameters>
          <param key="checkInterval">300000</param>
          <param key="batchCount">100</param>
        </parameters>
      </task>
    </tasks>
  </service.tasks>

  <system.net>
    <connectionManagement>
      <add address="*" maxconnection="48" />
    </connectionManagement>
  </system.net>
  <system.runtime.remoting>
    <application name="server">
      <channels>
        <channel ref="tcp" port="8090">
          <serverProviders>
            <formatter ref="soap" typeFilterLevel="Full" />
            <formatter ref="binary" typeFilterLevel="Full" />
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup> 

</configuration>

如何更改service.tasks标记和system.runtime.remoting标记内的值。

1 个答案:

答案 0 :(得分:2)

请参阅此代码以更新 ExpireRequirements 任务元素中的 entityID 值(在参数中指定配置文件路径:void my_libav::SetStreamLoggingCallback(STREAM_LOGGING_CALLBACK_CB p_stream_logger) { mp_stream_logging_callback = p_stream_logger; } void my_libav::RedirectLoggingOutputs(void *ptr, int level, const char *fmt, va_list vargs ) { std::string msg; ... if (g_mylibav->mp_stream_logging_callback) g_mylibav->mp_stream_logging_callback(msg); } ):

Mock<UserManager<User>> userManagerMock = new Mock<UserManager<User>>();
userManagerMock
    .Setup(m => m.FindByNameAsync(It.IsAny<string>()))
    .Returns(Task.FromResult(It.IsAny<User>()));