Создание DockerFile в Visual Studio не работаетC#

Место общения программистов C#
Ответить
Anonymous
 Создание DockerFile в Visual Studio не работает

Сообщение Anonymous »

Я пытаюсь контейнеризировать свое приложение .NET 8 с помощью Docker. Мой проект имеет следующую структуру:

Код: Выделить всё

/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
Я сгенерировал файл докеров с помощью поддержки VisualStudio. Единственное изменение, которое я сделал, — это переместить файл докеров в корень проекта, чтобы команды в сгенерированном файле имели больше смысла.< /p>

Код: Выделить всё

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/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"]
Но это не работает, когда я запускаю docker build -t myapp-api. (в корневой папке моего проекта).
И я получаю эту ошибку в качестве возврата

Код: Выделить всё

[+] 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.com/dotnet/sdk:8.0                            0.2s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:8.0                         0.2s
=> [internal] load .dockerignore                                                            0.0s
=> => transferring context: 464B                                                            0.0s
=> [build  1/11] FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:b27b1354af00b7d4c922d74084f5  0.0s
=> => resolve mcr.microsoft.com/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.com/dotnet/aspnet:8.0@sha256:587c1dd115e4d6707ff656d30ace  0.0s
=> => resolve mcr.microsoft.com/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
Извините за многословный пост, но я

Код: Выделить всё

m struggling for the past hours with this error. I
уже проверил папки SRC/SRC, чтобы проверить, было ли это некоторое избыточное значение. /p>
может кто -нибудь мне помочь?>

Подробнее здесь: https://stackoverflow.com/questions/793 ... ot-working
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»