title: Use Azure Key Vault Secrets for Unit Tests in Azure Pipelines
body: <p>I have a solution in .NET 5 with some Unit Tests in NUnit that required some secrets to work correctly. Testing in Visual Studio using local user secrets works fine but now I want to try to integrate using Azure Key Vault and run the Unit Tests inside a Pipeline.</p>
  <p>I added the Task <code>AzureKeyVault@2</code> and according to the log the secrets are <em>downloaded</em> just fine but in the next steps, the Unit Tests fail because it doesn't find some keys when try to access from <code>IConfiguration</code>.</p>
  <p>This is my <code>azure-pipelines.yml</code> (only the relevant parts).</p>
  <pre class="lang-yaml prettyprint-override"><code>- job: Init
    displayName: Unit Testing
    variables:
      solutionToBuild: 'Solution.sln'
      unitTestsProject: 'UnitTests\UnitTests.csproj'
      buildConfiguration: 'Release'
    steps:
    - task: DotNetCoreCLI@2
      displayName: 'Restore Packages'
      inputs:
        command: 'restore'
        projects: '$(solutionToBuild)'
        verbosityRestore: minimal
        feedsToUse: 'select'
  
    - task: DotNetCoreCLI@2
      displayName: 'Build Solution'
      inputs:
        command: 'build'
        projects: '$(solutionToBuild)'
        arguments: '-c $(buildConfiguration)'
  
    - task: AzureKeyVault@2
      displayName: 'Configure Key Vault'
      inputs:
        azureSubscription: '**-etc-**'
        KeyVaultName: '**key-vault-name**'
  
    - task: DotNetCoreCLI@2
      displayName: 'Run Unit Tests'
      inputs:
        command: 'test'
        projects: '$(unitTestsProject)'
        arguments: '-c $(buildConfiguration) --collect:&quot;XPlat Code Coverage&quot;'
        publishTestResults: true
  </code></pre>
  <p>I created this basic tests that are currently failing in the Pipeline. I'm using the <code>Host.CreateDefaultBuilder()</code> method to initialize all the unit tests.</p>
  <pre class="lang-cs prettyprint-override"><code>[Test]
  [TestCase(&quot;secret-key-1&quot;)]
  [TestCase(&quot;secret-key-1&quot;)]
  public void TestSecrets(string key)
  {
      Assert.NotNull(_config[key]);
      Assert.IsNotEmpty(_config[key]);
  }
  </code></pre>
  <p>Does the <code>AzureKeyVault@2</code> pass the secrets keys and values for the <code>DotNetCoreCLI@2</code> task or do I need an additional step?. I read that you can play with the <a href="https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/file-transform?view=azure-devops" rel="nofollow noreferrer">FileTransform@1</a> step using an empty <code>appsettings.json</code> but I couldn't make it work. Is there a correct method to achieve this?</p>