0
votes

What do I have

  • In my release pipeline I use IIS Web App Deployment Task that does a variable substitution in appsettings.json:

    task screenshot

  • I want to run some integration and end to end tests:

    enter image description here

Question

  1. How do I replace settings appsettings.json related to my test projects.
  2. How do I force the test runner to use a specific environment, e.g Staging, so that appsettings.Staging.json will is picked?
1
You can try to add a separate file transform task. In addition, can you elaborate on the relationship between appsettings.json and test?user13142267
@HiGuy: That solves #1. I've solved #2 as well, but won't mark it as answer just yet, in case you have better idea.Liero

1 Answers

0
votes
  1. How do I replace settings appsettings.json related to my test projects.

    There is File Trasnform task that does the variable substitution exactly like IIS Web App Deployment Task but in a separate step.


  1. How do I force the test runner to use a specific environment, e.g Staging, so that appsettings.Staging.json will is picked?

    Environment variables like ASPNETCORE_ENVIRONMENT can be configured in a .runsettings file:

     <?xml version="1.0" encoding="utf-8"?>
     <RunSettings>
       <RunConfiguration>
         <EnvironmentVariables>
           <ASPNETCORE_ENVIRONMENT>Development</ASPNETCORE_ENVIRONMENT>
         </EnvironmentVariables>
       </RunConfiguration>
     </RunSettings>
    

    The value of environment variable can be then replaced in a separate pipeline step. I've used powershell task:

     steps:
     - powershell: |
        $fileName = "$(System.DefaultWorkingDirectory)/MyBuildArtifact/test.runsettings";
        [xml]$xml = Get-Content $fileName
        $xml.SelectSingleNode("//ASPNETCORE_ENVIRONMENT").InnerText = "$(System.StageDisplayName)";
        $xml.Save($fileName);
       failOnStderr: true
       showWarnings: true
       displayName: 'Configure ASPNETCORE_ENVIRONMENT'
    

I also needed to make sure the test.runsettings file is included in my build artifact and configure the Visual Studio Test task to use that file