覆盖TestRun参数,其值包括Visual Studio Team Services中的半冒号

问题描述 投票:5回答:1

我的runsettings文件包含很少的连接字符串,我希望能够在VSTS中覆盖这些连接字符串,具体取决于环境。

我不想为每个环境使用特定的runsettings文件,但我想使用环境变量以便在配置我们的其他部署版本时保持一致。

但是,当我想向单元测试转发包含分号(;)的连接字符串(或任何参数)时,我将遇到问题。它被截断了。我测试过没有“;”传输其他值成功。

environment variables

task configuration

settings.runsettings

        <?xml version="1.0" encoding="utf-8"?>
        <RunSettings>
          <TestRunParameters>
           <Parameter name="CRM_CONNECTIONSTRING" value="Url = https://MYCRM.crm4.dynamics.com; [email protected]; Password=mypassword;" />
          <TestRunParameters>        
         </RunSettings>

但是,当执行(并显示单元测试中收到的实际值)时,该值在第一个“;”之后被截断。

enter image description here

有没有办法保护价值?

azure-pipelines-release-pipeline
1个回答
4
投票

在直接联系microsoft之后,最终回答了自己的解决方法。

问题出现在官方的任务github:https://github.com/Microsoft/vsts-tasks/issues/2567

解决方法:在测试程序集任务之前,运行一个powershell脚本,将runsettings文件的路径作为参数,读取VSTS环境变量并在runsettings中替换direcly XML值。

我在这里提供了我的powershell脚本:https://github.com/camous/vsts-powershell/blob/master/Set-RunSettings.ps1(参数必须以“__”为前缀)

我在这里写了一个更完整的“如何”:https://stuffandtacos.azurewebsites.net/2016/09/28/override-runsettings-parameters-in-visual-studio-team-service-when-value-contains-semi-colons/

© www.soinside.com 2019 - 2024. All rights reserved.