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
Hi everybody,
I have a bit different problem in a similar solution, the class library code reference a com library (Microsoft.Office.Interop.MSProject.dll), this code give error says this operating system does not support this code, the container targets Linux, how to make a docker file that makes possible compatibility for com library in container that target Linux
[…] project with class library dependecies throws error, that the dependent library was not found and this article says I should move Docker file to solution level. But I have another API project in the solution […]
This blog post 4 years ago worked wonderfully for me to get my ASp.NET Core 7 mvc up and running on an n-tier architecture design on my digital ocean droplet.
I’m using Dokku to deploy the application and it required the Dockerfile to be in the root, and this blog post was such a smooth experience for me to follow I have to comment to congratulate you 😉