3

I'm trying to build my ASP.Net Core using a build pipeline in Azure devops and get an error when running a script to script the ef migration.

I do not have the production connection string in the appsettings.json file on purpose. The production connection string populated in the Configuration section of the app service. I know the web application can connect to the database as I have published using Visual Studio and tables have been created in the production database and also can read/save to/from the DB.

the script I'm running is:

dotnet ef migrations script -i -o $(build.artifactstagingdirectory)\scripts.sql --project $(Build.SourcesDirectory)\MyApp\MyApp.csproj --startup-project $(Build.SourcesDirectory)\MyApp\MyApp.csproj

The error in the script output is:

System.ArgumentNullException: Value cannot be null. Parameter name: connectionString

So the question I have is how can I pass the production connection string to the ef migrations command without having the connection string in the appsettings.json file?

1
  • 1
    change the environment by ASPNETCORE_ENVIRONMENT=Production, and then the dotnet ef migrations command will handle it automatically. Commented Apr 26, 2019 at 5:24

1 Answer 1

0

Azure DevOps can't access your WebApp configuration out of the box. You could read them with a custom script using the Azure API's, but I don't recommend that, since that API also could get other Information about your Azure Setup.

I recommend that you move the configuration (or the shared part of it) to an Azure Key Vault, then you can easily use the configuration from both .NET Core apps and Azure DevOps.

Afterwards when Azure DevOps has your configured ConnectionString in it's Environment, the usual dotnet ef migrations command should work.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.