简体   繁体   中英

dotnet publish fails during docker build

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM