Can't publish docker image of a dotnet 5 project from github actions with dependencies in projects stored in another github repository

We have a web platform with multiple applications created with dotnet 5. Each application has an individual solution in Visual Studio and an individual GitHub repository. Each repository contains a single Web project, and each solution references one or more projects stored in another repository. This repository is called Commons and contains the projects of Data Access, CacheLayer, Services, etc. The rest of solutions has at least one reference of any of these projects.

We are using GitHub Actions to build each project. In each project we have created a step in order to download the Commons repsitory. This is an example of our yml workflow:

name: Publish Docker Web

    branches: [ master ]
    branches: [ master ]


    runs-on: ubuntu-latest

    - uses: actions/checkout@v2
    - name: check out commons
      uses: actions/checkout@v2
        repository: myteam/Commons
        token: ${{ secrets.MY_PAT }}
        path: ./Commons
        ref: main
    - name: change folder
      run: |
        cd ..
        mv Web/Commons Commons
        cd Web
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
        dotnet-version: 5.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --no-restore
    - name: Setup Docker
      uses: docker-practice/actions-setup-docker@v1
        docker_daemon_json: '{"insecure-registries":["my.docker.server"]}'
    - name: Docker login
      uses: docker/login-action@v1
       username: ${{ secrets.DOCKERHUB_USERNAME }}
       password: ${{ secrets.DOCKERHUB_TOKEN }}
       registry: ${{ secrets.DOCKERHUB_SERVER }}
    - name: Build and push Docker image
      uses: docker/build-push-action@v2
       push: true
       file: Web/Dockerfile
       tags: user/app:latest

The build step is successfull, but when it tries to create the docker image, it fails. This is our docker file:

FROM AS build-env
COPY ../Commons ./
COPY Web/Web.csproj ./
RUN dotnet restore

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

COPY --from=build-env /app/out .
# ENTRYPOINT ["dotnet", "Web.dll"]

We have added the line COPY ../Commons ./ to the default dockerfile, trying to copy the Commons libraries to the WORKDIR, but it didn’t work. Without that line, the publish command fails because it doesn’t find any common library:

#10 1.652   Skipping project "/Commons/DataAccess/DataAccess.csproj" because it was not found.
Error: #10 9.700 /app/Web/Controllers/HomeController.cs(37,276): error CS0246: The type or namespace name 'EntityContext' could not be found (are you missing a using directive or an assembly reference?) [/app/Web/Web.csproj]

If we add that line, it fails because the directory …/Commons doesn’t exists:

Error: buildx call failed with: error: failed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/Commons" not found: not found

The directory structure in the build process is like this:


The problem is that we don’t find the way to copy the Commons directory into the WORKDIR. We have tested multiple choices but any of them has worked. Can anyone help us? How can we copy the Commons directory to the WORKDIR?

PS: We have discarded the possibility to add each common library through a nuget package because they change frequently and we think it will add so much complexity to our development process, but any idea is welcomed.


We have found the problem, the github action docker/build-push-action@v2 downloads the source code from the repository again. The changes we have made in the local directory are omitted.

There are any other github actions to create the docker image and do the push to a docker registry?

We have found some github actions that seems to do these, but we don’t know if they are trusted.