I am creating a sample EF Core project using SQL Server and deploying it in Azure.
As of now, I have a BookingAPI
service and there are 2 class libraries which are called SharedServices
and Domains
.
BookingAPI
does NOT have an ApplicationDBContext
. The Domains
project has an ApplicationDBContext
and all the domains are also, inside it.
BookingAPI
is calling the Domains
project to access the database.
The project structure looks like this
- BookingServices (Folder)
- BookingAPI (ASP.NET Core Web API)
- Program.cs
- appsettings.json
- appsettings.Development.json
- appsettings.Production.json
- SharedServices (Folder)
- SharedServices (class library)
- Domains (class library)
- Data (Folder)
-ApplicationDBContext
- Migrations (Folder)
- Migration1
- Migration2
- Tables (Folder)
- Bookings.cs
- Tables.cs
As long as I was working in my local, it was completely fine. I could create migrations, and update the database.
But I want to deploy this project to Azure.
For that, I created a database in Azure and also published it from Visual Studio.
However, I am facing the following problems while publishing the BookingAPI
to Azure:
-
If I add my connection strings in
appsettings.Development.json
andappsettings.Production.json
, the Azure publisher can not find them. If I add them toappsettings.json
, then they can be found. -
Even if I referenced the
Domains
project properly (I am usingDbContext
for database update fromBookingAPI
), and there are migrations in theDomains
project, these migrations are not found during publish and are not applied to the Azure database.
I am stuck here and can’t find any context:
Now after waiting long enough I am getting this error in Publish page
Can anyone help me through this problem ?
Thanks!
2
Answers
The Problem is solved now. The main reason behind this problem was that my project was made in .net core 7 and the azure environment I was installing my service was .net core 8. I had to recreate the projects using .net core 8.
When working with different ENVIRONMENT, there are things you need to pay attention to when Publishing. Apparently appsettings.json is set by default because you didn’t specify an environment when publishing.
If you have made all the environment settings, publishing for the Production environment will be enough.
and an example for the production environment
Reference