简体   繁体   English

docker build 期间 dotnet 发布失败

[英]dotnet publish fails during docker build

First of all, I am sorry if I misinterpret what I get, I'm completly new to Docker.首先,如果我误解了我得到的东西,我很抱歉,我对 Docker 完全陌生。

So I'm developping a software to process csv files into a database, and everything runs in GCP.所以我正在开发一个软件来将 csv 文件处理成数据库,一切都在 GCP 中运行。 To run my code, I have access to a Cloud Run that can use Docker images.为了运行我的代码,我可以访问可以使用 Docker 映像的 Cloud Run。

Today I added 3 new files :今天我添加了 3 个新文件:

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

Prior to these modifications, I had to run 3 commands to publish my code on the cloud run :在进行这些修改之前,我必须运行 3 个命令才能在云运行上发布我的代码:

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. /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets(295,5):错误NETSDK1022:包含重复的“编译”项目。 The .NET SDK includes 'Compile' items from your project directory by default.默认情况下,.NET SDK 包括项目目录中的“编译”项。 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.您可以从项目文件中删除这些项目,或者如果要在项目文件中明确包含它们,将“EnableDefaultCompileItems”属性设置为“false”。 For more information, see https://aka.ms/sdkimplicititems .有关更多信息,请参阅https://aka.ms/sdkimplicititems The duplicate items were: 'BusinessLogic/Repository/AcademyRepository.cs';重复项是:“BusinessLogic/Repository/AcademyRepository.cs”; 'BusinessLogic/Repository/Interfaces/ISourceRepository.cs'; 'BusinessLogic/Repository/Interfaces/ISourceRepository.cs'; 'BusinessLogic/Repository/SourceRepository.cs' [/app/MyProject.csproj] '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.我在多个线程上看到要检查 .csproj 文件中是否有奇怪的...条目,但我的中没有这样的东西。

And here is my dockerfile :这是我的 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我尝试运行在 gcloud builds submit 命令之外失败的命令,但没有发生任何错误

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.编辑:从 Visual Studio 编辑 csproj 文件不会向您显示实际文件,而是向您显示修改后的版本。 I edited the csproj with notepad, cleaned then recompiled the project but the problem is still here.我用记事本编辑了csproj,清理然后重新编译项目,但问题仍然存在。

Found a workaround :找到了一个解决方法:

Here is a part of my architecture :这是我的架构的一部分:

BusinessLogic
--- Repositories
    --- Interface

The problem resides in the "Interface" folder.问题出在“Interface”文件夹中。 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仍然不知道如何解决真正的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 dotnet 构建或发布期间无法找到包含目录的存储库 - Unable to locate repository containing directory during dotnet build or publish dotnet发布不包括在构建后事件期间生成的文件 - dotnet publish doesn't include files generated during post build event 使用 NuGet Microsoft.NET.Build.Containers 使用新的隐式 dockerfile 功能发布 do.net 在 GitLab cicd 中失败 - dotnet publish with new implicit dockerfile feature using NuGet Microsoft.NET.Build.Containers fails in GitLab cicd do.net build 和 do.net publish 命令有什么区别? - What is the difference between dotnet build and dotnet publish commands? 无法为 Azure Edge 构建 docker C#,错误 [build-env 6/6] RUN dotnet publish -c Release -o out - Unable to built docker C# for Azure Edge , ERROR [build-env 6/6] RUN dotnet publish -c Release -o out Azure DevOps Build Pipeline:“publish”命令正在执行“dotnet build”而不是“dotnet publish” - Azure DevOps Build Pipeline: 'publish' command is executing 'dotnet build' instead of 'dotnet publish' Docker:dotnet ef数据库更新失败 - Docker: dotnet ef database update fails Docker - do.net 恢复无法连接到私人订阅源 - Docker - dotnet restore fails connection to private feeds dotnet build xamarin 项目使用控制台失败 - dotnet build xamarin project fails using console docker 中的“do.net 发布”不包括“运行时”文件夹 - .NET 5 SDK - 对于 AWS Lambda - 'dotnet publish' in docker not including 'runtimes' folder - .NET 5 SDK - for AWS Lambda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM