Imran
.NET, Azure, Container

Dockerize .NET CORE web App with dependent class library

Recently one of the challenges i faced while containerize the application was to create the docker image of my web project where it has dependent class library , in short more than one .csproj files. 

I created .NET core project and added dependent class library project, however i couldn’t create image since both projects were not sitting on the same level so i struggled a bit to find the solution and here is my experience.

Create .NET Project 

First I created a dot net core project (WebApp) with “Enable Docker Support”.

The Default Docker File looks like this.

Reference Class Library project

I added a new class Library Project and added reference of this project to WebApp. 

Simple message in the dependent class library.

The main project is referencing the dependent library class.

Displaying the message.

Build Docker Images

I tried to build the existing docker image But Got error in the end and we can see the reason it skipped the “DependentClassLib”

Solution

The simple solution is to move the docker file out of this project and place it at the solution level so docker file gets aware of both the projects (Main and dependent). 

I updated the docker file and it looks like this. If you notice we are now copying dependent and Main project into source folder before actually restoring/building it

After running the build again , i am able to create the image successfully.

Running the docker container now produces

Like the post ? Share !

Related posts

Modern Web Apps Architecture with AWS Fargate

Imran
August 20, 2019

Azure Logic Apps – Approval Workflow using HTML Form

Imran
June 7, 2020

Containerize and Migrate Legacy Classic ASP to Azure App Service

Imran
January 5, 2020
Exit mobile version