1

I added an integration test project in my Solution, using .NET Core 3.1 and xUnit. In this test project I also added an appsettings.json with a connectionstring that should be used locally.

  "ConnectionStrings": {
    "DefaultConnection": "Data Source=(LocalDb)\\MSSQLLocalDb;Initial Catalog=MyApp_IntegrationTests;Integrated Security=True"
  }

I also added the following in my build pipeline in Azure DevOps:

- task: DotNetCoreCLI@2
  displayName: 'Run integration tests'
  inputs:
    command: test
    projects: '**/*Tests.csproj'
    arguments: '--configuration $(buildConfiguration)'

This fails because Azure does not support LocalDB. This makes sense, but i can't figure out how to transform the appsettings.json used by the test project in the pipeline. If I put in the Azure connectionstring in the appsettings.json and commit it, it works as expected.

Any suggestions on how I can fix this?

Jan V
  • 127
  • 8

2 Answers2

2

If you want to replace the LocalDB connectionString with Azure connectionstring in your pipeline. You can use variable substitution tasks(eg. Magic Chunks extension) to replace the connectionString in appsettings.json.

First you need set a variable(eg. MyConnectionString) in you pipeline to hold the value of Azure connectionstring.

Then you can add Config Transfromation Task before the Dotnet Test Task, and refer to this variable using the syntax $(MyConnectionString) in the Config Transfromation Task to replace the LocalDB connectionString.

You can check out the example in this thread.

Another workaround is to use self-host agent to build your pipeline. Since Azure agents cannot communicate with your localDB, you can set up a self-hosted agent on your local machine. Your localDB is accesible to the self-hosted agent.

Hope above helps!

Community
  • 1
  • 1
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
1

You can start LocalDB on Azure DevOps will the following script

- script: sqllocaldb start mssqllocaldb
Kevin Smith
  • 13,746
  • 4
  • 52
  • 77
  • This command does not work, i added the following: - task: PowerShell@2 displayName: 'start mssqllocaldb' inputs: targetType: 'inline' script: 'sqllocaldb start mssqllocaldb' But i keep getting ' The term 'sqllocaldb' is not recognized as the name of a cmdlet'. I its running on a 'Ubuntu-16.04' image. Could that be the isse? – Jan V Apr 03 '20 at 12:04
  • Oh yeah, this is only installed on the windows images – Kevin Smith Apr 03 '20 at 12:39