admin管理员组文章数量:1193328
I am trying to containerize my .NET 8 application using Docker. My project has the following structure:
/MyApp
│── solution.sln
│── src
│ ├── Adapters
│ │ ├── MyApp.API
│ │ │ ├── MyApp.API.csproj
│ ├── Core
│ │ ├── MyApp.Application
│ │ │ ├── MyApp.Application.csproj
│ │ ├── MyApp.Domain
│ │ │ ├── MyApp.Domain.csproj
│ │ ├── MyApp.Infrastructure
│ │ │ ├── MyApp.Infrastructure.csproj
│ ├── CrossCutting
│ │ ├── MyApp.CrossCutting
│ │ │ ├── MyApp.CrossCutting.csproj
│ ├── Tests
│ │ ├── MyApp.Tests
│ │ │ ├── MyApp.Tests.csproj
I generated the dockerfile using the Visual Studio support, the only change that I made was to move the dockerfile to the root of the project, so the commands in the generated file make more sense.
FROM mcr.microsoft/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
# Copy only .csproj files first for better caching
COPY ["src/Adapters/MyApp.API/MyApp.API.csproj", "src/Adapters/MyApp.API/"]
COPY ["src/Core/MyApp.Application/MyApp.Application.csproj", "src/Core/MyApp.Application/"]
COPY ["src/Core/MyApp.Domain/MyApp.Domain.csproj", "src/Core/MyApp.Domain/"]
COPY ["src/Core/MyApp.Infrastructure/MyApp.Infrastructure.csproj", "src/Core/MyApp.Infrastructure/"]
COPY ["src/CrossCutting/MyApp.CrossCutting/MyApp.CrossCutting.csproj", "src/CrossCutting/MyApp.CrossCutting/"]
# Restore dependencies
RUN dotnet restore "./src/Adapters/MyApp.API/MyApp.API.csproj"
# Copy the entire source code after restoring dependencies
COPY . .
# Move to the API directory
WORKDIR "/src/src/Adapters/MyApp.API"
# Build the API
RUN dotnet build "./MyApp.API.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./MyApp.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.API.dll"]
But is not working. When I run docker build -t myapp-api .
(at the root folder of my project), I get this error:
[+] Building 28.2s (19/21) docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 1.36kB 0.0s
=> [internal] load metadata for mcr.microsoft/dotnet/sdk:8.0 0.2s
=> [internal] load metadata for mcr.microsoft/dotnet/aspnet:8.0 0.2s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 464B 0.0s
=> [build 1/11] FROM mcr.microsoft/dotnet/sdk:8.0@sha256:b27b1354af00b7d4c922d74084f5 0.0s
=> => resolve mcr.microsoft/dotnet/sdk:8.0@sha256:b27b1354af00b7d4c922d74084f5c8a5cbf5 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 12.86kB 0.0s
=> [base 1/2] FROM mcr.microsoft/dotnet/aspnet:8.0@sha256:587c1dd115e4d6707ff656d30ace 0.0s
=> => resolve mcr.microsoft/dotnet/aspnet:8.0@sha256:587c1dd115e4d6707ff656d30ace5da9f 0.0s
=> CACHED [base 2/2] WORKDIR /app 0.0s
=> CACHED [final 1/2] WORKDIR /app 0.0s
=> CACHED [build 2/11] WORKDIR /src 0.0s
=> CACHED [build 3/11] COPY [src/Adapters/MyApp.API/MyApp.API.csproj, src/Adapters/PetZ 0.0s
=> CACHED [build 4/11] COPY [src/Core/MyApp.Application/MyApp.Application.csproj, src/C 0.0s
=> [build 5/11] COPY [src/Core/MyApp.Domain/MyApp.Domain.csproj, src/Core/MyApp.Domain 0.0s
=> [build 6/11] COPY [src/Core/MyApp.Infrastructure/MyApp.Infrastructure.csproj, src/Co 0.1s
=> [build 7/11] COPY [src/CrossCutting/MyApp.CrossCutting/MyApp.CrossCutting.csproj, sr 0.0s
=> [build 8/11] RUN dotnet restore "./src/Adapters/MyApp.API/MyApp.API.csproj" 23.9s
=> [build 9/11] COPY . . 0.2s
=> [build 10/11] WORKDIR /src/src/Adapters/MyApp.API 0.0s
=> ERROR [build 11/11] RUN dotnet build "./MyApp.API.csproj" -c Release -o /app/build 3.7s
------
> [build 11/11] RUN dotnet build "./MyApp.API.csproj" -c Release -o /app/build:
0.840 Determining projects to restore...
0.844 Skipping project "/src/src/core/MyApp.Application/MyApp.Application.csproj" because it was not found.
0.844 Skipping project "/src/src/core/MyApp.Infrastructure/MyApp.Infrastructure.csproj" because it was not found.
0.865 Skipping project "/src/src/core/MyApp.Application/MyApp.Application.csproj" because it was not found.
0.865 Skipping project "/src/src/core/MyApp.Infrastructure/MyApp.Infrastructure.csproj" because it was not found.
1.192 All projects are up-to-date for restore.
3.137 MyApp.CrossCutting -> /app/build/MyApp.CrossCutting.dll
3.149 /usr/share/dotnet/sdk/8.0.405/Microsoft.Common.CurrentVersion.targets(2176,5): warning : The referenced project '../../core/MyApp.Application/MyApp.Application.csproj' does not exist. [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.149 /usr/share/dotnet/sdk/8.0.405/Microsoft.Common.CurrentVersion.targets(2176,5): warning : The referenced project '../../core/MyApp.Infrastructure/MyApp.Infrastructure.csproj' does not exist. [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(8,26): error CS0234: The type or namespace name 'Services' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(10,14): error CS0234: The type or namespace name 'Domain' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(11,14): error CS0234: The type or namespace name 'Domain' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(12,14): error CS0234: The type or namespace name 'Domain' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(13,14): error CS0234: The type or namespace name 'Domain' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(14,14): error CS0234: The type or namespace name 'Infrastructure' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(15,14): error CS0234: The type or namespace name 'Infrastructure' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/Auth/AuthController.cs(5,26): error CS0234: The type or namespace name 'Handlers' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/Pet/PetController .cs(4,26): error CS0234: The type or namespace name 'Dto' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/Pet/PetController .cs(5,26): error CS0234: The type or namespace name 'Handlers' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(4,26): error CS0234: The type or namespace name 'Dto' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(5,26): error CS0234: The type or namespace name 'Dto' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(6,26): error CS0234: The type or namespace name 'Handlers' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(7,26): error CS0234: The type or namespace name 'Handlers' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Middleware/AuthenticationMiddleware.cs(4,26): error CS0234: The type or namespace name 'Dto' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Middleware/AuthenticationMiddleware.cs(5,26): error CS0234: The type or namespace name 'Resources' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Program.cs(1,7): error CS0246: The type or namespace name 'FluentValidation' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Middleware/AuthenticationMiddleware.cs(15,43): error CS0246: The type or namespace name 'Messages' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/Pet/PetController .cs(26,58): error CS0246: The type or namespace name 'CreatePetRequest' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(28,58): error CS0246: The type or namespace name 'CreateUserRequest' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Middleware/AuthenticationMiddleware.cs(17,140): error CS0246: The type or namespace name 'Messages' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.578 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(37,66): error CS0246: The type or namespace name 'FinishUserRegistrationRequest' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.585
3.585 Build FAILED.
3.585
3.586 /src/src/CrossCutting/MyApp.CrossCutting/Auth/TokenProvider.cs(25,46): warning CS8604: Possible null reference argument for parameter 's' in 'byte[] Encoding.GetBytes(string s)'. [/src/src/CrossCutting/MyApp.CrossCutting/MyApp.CrossCutting.csproj]
3.586 /src/src/CrossCutting/MyApp.CrossCutting/Auth/TokenProvider.cs(50,46): warning CS8604: Possible null reference argument for parameter 's' in 'byte[] Encoding.GetBytes(string s)'. [/src/src/CrossCutting/MyApp.CrossCutting/MyApp.CrossCutting.csproj]
3.586 /src/src/CrossCutting/MyApp.CrossCutting/Auth/TokenProvider.cs(70,24): warning CS8603: Possible null reference return. [/src/src/CrossCutting/MyApp.CrossCutting/MyApp.CrossCutting.csproj]
3.586 /usr/share/dotnet/sdk/8.0.405/Microsoft.Common.CurrentVersion.targets(2176,5): warning : The referenced project '../../core/MyApp.Application/MyApp.Application.csproj' does not exist. [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /usr/share/dotnet/sdk/8.0.405/Microsoft.Common.CurrentVersion.targets(2176,5): warning : The referenced project '../../core/MyApp.Infrastructure/MyApp.Infrastructure.csproj' does not exist. [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(8,26): error CS0234: The type or namespace name 'Services' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(10,14): error CS0234: The type or namespace name 'Domain' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(11,14): error CS0234: The type or namespace name 'Domain' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(12,14): error CS0234: The type or namespace name 'Domain' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(13,14): error CS0234: The type or namespace name 'Domain' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(14,14): error CS0234: The type or namespace name 'Infrastructure' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Configuration/DependencyInjection.cs(15,14): error CS0234: The type or namespace name 'Infrastructure' does not exist in the namespace 'MyApp' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/Auth/AuthController.cs(5,26): error CS0234: The type or namespace name 'Handlers' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/Pet/PetController .cs(4,26): error CS0234: The type or namespace name 'Dto' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/Pet/PetController .cs(5,26): error CS0234: The type or namespace name 'Handlers' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(4,26): error CS0234: The type or namespace name 'Dto' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(5,26): error CS0234: The type or namespace name 'Dto' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(6,26): error CS0234: The type or namespace name 'Handlers' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(7,26): error CS0234: The type or namespace name 'Handlers' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Middleware/AuthenticationMiddleware.cs(4,26): error CS0234: The type or namespace name 'Dto' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Middleware/AuthenticationMiddleware.cs(5,26): error CS0234: The type or namespace name 'Resources' does not exist in the namespace 'MyApp.Application' (are you missing an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Program.cs(1,7): error CS0246: The type or namespace name 'FluentValidation' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Middleware/AuthenticationMiddleware.cs(15,43): error CS0246: The type or namespace name 'Messages' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/Pet/PetController .cs(26,58): error CS0246: The type or namespace name 'CreatePetRequest' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(28,58): error CS0246: The type or namespace name 'CreateUserRequest' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Middleware/AuthenticationMiddleware.cs(17,140): error CS0246: The type or namespace name 'Messages' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 /src/src/Adapters/MyApp.API/Controllers/User/UserController.cs(37,66): error CS0246: The type or namespace name 'FinishUserRegistrationRequest' could not be found (are you missing a using directive or an assembly reference?) [/src/src/Adapters/MyApp.API/MyApp.API.csproj]
3.586 5 Warning(s)
3.586 22 Error(s)
3.586
Sorry for the verbose post, but I've been struggling for the past hours with this error.
I've already checked the src/src folders to check if it wasn't some redundance.
I have already tried to remove the src/src and tested different paths, but that didn't solve my problem.
Can anyone help me?
Thanks
本文标签: cVisual Studio DockerFile generated not workingStack Overflow
版权声明:本文标题:c# - Visual Studio DockerFile generated not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738457064a2087815.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论