10

How should I reference a project in project file so Docker build finds the projects?

Project file:

<ItemGroup>
    <ProjectReference Include="..\Assets.Core\Assets.Core.csproj" />
    <ProjectReference Include="..\Creator.Components\Creator.Components.csproj" />
    <ProjectReference Include="..\LC.Components.Core\LC.Components.Core.csproj" />
    <ProjectReference Include="..\LC.Components\LC.Components.csproj" />
</ItemGroup>

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
EXPOSE 80
EXPOSE 443

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /DIRPATH
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Creator.Demo.dll"]

Output:

Determining projects to restore... Skipping project "C:\Assets.Core\Assets.Core.csproj" because it was not found.
Skipping project "C:\Creator.Components\Creator.Components.csproj" because it was not found. Skipping project "C:\LC.Components.Core\LC.Components.Core.csproj" because it was not found. Skipping project "C:\LC.Components\LC.Components.csproj" because it was not found. Skipping project "C:\Assets.Core\Assets.Core.csproj" because it was not found.
Skipping project "C:\Creator.Components\Creator.Components.csproj" because it was not found. Skipping project "C:\LC.Components.Core\LC.Components.Core.csproj" because it was not found. Skipping project "C:\LC.Components\LC.Components.csproj" because it was not found. Restored C:\app\creator.demo.csproj (in 282 ms).

2

1 Answer 1

15
+50

Is complicated to explaind, why is not posible to build Dockerfile from same project space, then I read this article [blog]: https://josiahmortenson.dev/blog/2020-06-08-aspnetcore-docker-https and finaly understud how I need to run the build.

In my case:

/src
 .sln
 /project1
   project1.csproj
   Dockerfile
 /project2
   project2.csproj
   Dockerfile
 /reference1
   reference1.csproj
 /reference2
   reference2.csproj

Is necesary to move to /src level for run command

docker build -t {nametagedcontainer} -f project1/Dockerfile .

Finally

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS c
WORKDIR /app   

    
COPY ["project1/project1.csproj", "project1/"]
COPY ["reference1/reference1.csproj", "reference1/"]
#others reference if necesary



RUN dotnet restore "project1/project1.csproj" 

COPY . .
WORKDIR "/app/project1"
RUN dotnet build "project1.csproj" -c Release -o /app/build

from c as publish
RUN dotnet publish "project1.csproj" -c Release -o /app/publish
 

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app 
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "{dllname}.dll"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.