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?
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.
Afterwards when Azure DevOps has your configured ConnectionString in it's Environment, the usual
dotnet ef migrations command should work.