2
votes

First of all, I am sorry if I misinterpret what I get, I'm completly new to Docker.

So I'm developping a software to process csv files into a database, and everything runs in GCP. To run my code, I have access to a Cloud Run that can use Docker images.

Today I added 3 new files :

  • 'BusinessLogic/Repository/AcademyRepository.cs'
  • 'BusinessLogic/Repository/Interfaces/ISourceRepository.cs'
  • 'BusinessLogic/Repository/SourceRepository.cs'

Prior to these modifications, I had to run 3 commands to publish my code on the cloud run :

dotnet build
gcloud builds submit --tag gcr.io/myproject/mytag
gcloud run deploy myservice gcr.io/myproject/mytag--platform managed

But since I added these files, I get the following error :

/usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets(295,5): error NETSDK1022: Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'BusinessLogic/Repository/AcademyRepository.cs'; 'BusinessLogic/Repository/Interfaces/ISourceRepository.cs'; 'BusinessLogic/Repository/SourceRepository.cs' [/app/MyProject.csproj]

I saw on multiple threads to check .csproj files for weird ... entries but there was nothing like this in mine.

And here is my dockerfile :

# Use Microsoft's official build .NET image.
# https://hub.docker.com/_/microsoft-dotnet-core-sdk/
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build
WORKDIR /app
 
# Install production dependencies.
# Copy csproj and restore as distinct layers.
COPY *.csproj ./
RUN dotnet restore
 
# Copy local code to the container image.
COPY . ./
WORKDIR /app
 
# Build a release artifact.
RUN dotnet publish -c Release -o out # This step fails
 
# Use Microsoft's official runtime .NET image.
# https://hub.docker.com/_/microsoft-dotnet-core-aspnet/
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS runtime

RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.8/main' >> /etc/apk/repositories && apk update --no-cache && apk add --no-cache bash libc6-compat=1.1.19-r11

WORKDIR /app
COPY --from=build /app/out ./
 
# Run the web service on container startup.
ENTRYPOINT ["dotnet", "MyDll.dll"]

I tried running the command that fails outside of the gcloud builds submit command but nothing wrong happened

If I delete the files and comment the related code, the problem vanishes ... but I kinda need those files

EDIT : Editing a csproj file from visual studio doesn't show you the actual file, it shows you a modified version. I edited the csproj with notepad, cleaned then recompiled the project but the problem is still here.

1
Your error says about duplicated source files - Pavel Anikhouski
From what I found on other topics and website, it usually is the case, but there should be a <ItemGroup> tag somewhere in my csproj, but when I edit my csproj file, I can only find nugget references - Adraekor
I'm having the same issue, I also don't have any includes in my csproj other than nuget packages. I can also create and run the docker image locally (Win 10 with WSL 2) without any errors. I'm also using .net 5.0 so the issue isn't resolved in the .net 5.0 sdk. - Shawn
Upon further investigation my issue seems to be with the depth of my project folder structure. Once I get 3 folders deep this issue happens. - Shawn

1 Answers

0
votes

Found a workaround :

Here is a part of my architecture :

BusinessLogic
--- Repositories
    --- Interface

The problem resides in the "Interface" folder. By deleting it and adding my interfaces in the parent folder (Repositories), the problem disappears. Still no idea how to solve the real problem though