从dockerfile运行dotnet publish -c释放-o out,错误-找不到项目文件“ /ProjectMe.Common/MyProject.Common.csproj”

时间:2018-10-26 15:40:48

标签: c# .net docker asp.net-core docker-compose

我的项目结构(解决方案)

  • src

  • projectMe.sln

内部src:

  • ProjectMe.Api
  • ProjectMe.Common
  • 服务

内部服务:

  • Services.Lot

ProjectMe.Api项目的Dockerfile:

FROM microsoft/dotnet:2.0-sdk AS build-env
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# copy everything else and build
COPY . ./

RUN dotnet publish -c Release -o out

# build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .

EXPOSE 80/tcp
ENTRYPOINT ["dotnet", "ProjectMe.Api.dll"]

我有docker-compose文件:

version: '3'

services:
  rabbitmq:
    image: "rabbitmq:3-management"
    hostname: "rabbitmq-localhost"
    container_name: rabbitmq
    ports:
      - "15672:15672"
      - "5672:5672"

  projectme.api:
    image: projectme/projectme.api 
    build:
      context: ./src/ProjectMe.Api
      dockerfile: Dockerfile
    ports: 
      - "8080:80"
    environment: 
      - ASPNETCORE_ENVIRONMENT=Development  
    # volumes: 
    #  - ./Projectme.api/bin/pub/:/app
    container_name: projectme.api
    depends_on:
      - service.lot

  service.lot:
    image: projectme/services.lot
    environment:
      - ConnectionString=Server=sql.data;User=sa;Password=Pass@word;Database=projectme.loans;    
      - ASPNETCORE_ENVIRONMENT=Development
    build:
      context: ./src/Services/Services.Lot
      dockerfile: Dockerfile
    ports: 
    - "8081:80"
    # volumes: 
    #  - ./Services.Lot/bin/pub/:/app
    container_name: service.lot
    depends_on:
      - sql.data
      - rabbitmq

  sql.data:
    # image: mssql-linux
    build:
      context: ./src/ProjectMe.Common/Database
      dockerfile: Dockerfile
    ports:
      - "5433:1433"
    container_name: mssql-linux

  user.data:
    image: redis

我运行docker-compose up -d并遇到此步骤错误:

    Building projectme.api
    Step 1/11 : FROM microsoft/dotnet:2.0-sdk AS build-env
     ---> 9e06837225a4
    Step 2/11 : WORKDIR /app
     ---> Using cache
     ---> 9ffccd44cc91
    Step 3/11 : COPY *.csproj ./
     ---> Using cache
     ---> 34b24faea5b3
    Step 4/11 : RUN dotnet restore
     ---> Using cache
     ---> ecfcdb36ee89
    Step 5/11 : COPY . ./
     ---> Using cache
     ---> 4113de886250
    Step 6/11 : RUN dotnet publish -c Release -o out

/usr/share/dotnet/sdk/2.1.202/NuGet.targets(928,5): warning MSB3202: The project file "/ProjectMe.Common/ProjectMe.Common.csproj" was not found. [/app/SupplyMe.Api.csproj]
/usr/share/dotnet/sdk/2.1.202/NuGet.targets(1019,5): warning MSB3202: The project file "/ProjectMe.Common/ProjectMe.Common.csproj" was not found. [/app/SupplyMe.Api.csproj]
...............................................................
...............................................................
Controllers/LotsController.cs(6,16): error CS0234: The type or namespace name 'Common' does not exist in the namespace 'ProjectMe' (are you missing an assembly reference?) [/app/ProjectMe.Api.csproj]
...............................................................
Service 'projectme.api' failed to build: The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1

Project ProjectMe引用了Services.Common。 当我没有docker dotnet publish -c Release -o out 项目的本地运行命令发布到文件夹时,没有错误。

能否请您帮我理解为什么找不到我的另一个项目ProjectMe.Common?如何解决这类错误?

0 个答案:

没有答案