Azure devops ASP.Net Core EF migration production connection string null

asp.net-core azure-devops entity-framework-core

Question

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
4/26/2019 1:43:49 AM

Popular Answer

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.

0
4/26/2019 6:00:44 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow