skip to Main Content

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:

  1. If I add my connection strings in appsettings.Development.json and appsettings.Production.json, the Azure publisher can not find them. If I add them to appsettings.json, then they can be found.

  2. Even if I referenced the Domains project properly (I am using DbContext for database update from BookingAPI), and there are migrations in the Domains 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:

enter image description here

Now after waiting long enough I am getting this error in Publish page

enter image description here

Can anyone help me through this problem ?

Thanks!

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    dotnet publish -c ASPNETCORE_ENVIRONMENT

    and an example for the production environment

    dotnet publish -c Production

    Reference

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search