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?

1
  • You can set your connection string as environment variable in your pipeline. Commented Apr 6, 2020 at 4:26

2 Answers 2

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!

Sign up to request clarification or add additional context in comments.

Comments

1

You can start LocalDB on Azure DevOps will the following script

- script: sqllocaldb start mssqllocaldb 

2 Comments

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?
Oh yeah, this is only installed on the windows images 🤔

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.