我正在尝试通过Jenkins在Docker容器中构建.NET核心MVC项目。我已经设置了从git中提取并在Docker容器内部构建的管道,但是当我尝试构建我的解决方案时,我不断收到这些错误。
我从https://docs.docker.com/engine/examples/dotnetcore/#create-a-dockerfile-for-an-aspnet-core-application获得了Dockerfile并为我的项目更改了它。它放在项目目录中与我的.sln文件位于同一文件夹中。出于某种原因,它失败了。我的文件结构似乎是正确的,但是脚本似乎无法在导入的环境中找到我的项目或构建工具。
错误文字(詹金斯)
[fundprofiles-docker_jenkins-B5GJFHQUL2XVSIUP7TPI255RMTFK5MJKMLIMBSXSXMQQJSZSEG5A] Running shell script
+ docker build -t e9f05c806e193d6c1920e5d5c23ed34350c4f491 -f Dockerfile .
Sending build context to Docker daemon 234.9MB
Step 1/9 : FROM microsoft/aspnetcore-build:2.0 AS build-env
---> 6105426f13e9
Step 2/9 : COPY *.sln ./
---> Using cache
---> 978a5d201ae0
Step 3/9 : RUN dotnet restore
---> Using cache
---> 2ac341942a6d
Step 4/9 : COPY . ./
---> 07c15ea85ca8
Step 5/9 : RUN dotnet publish -c Release -o out
---> Running in bf35842f7b24
Microsoft (R) Build Engine version 15.5.180.51428 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
/myapp/myapp.csproj(582,3): error MSB4019: The imported project "/usr/share/dotnet/sdk/2.1.4/Microsoft/VisualStudio/v15.0/WebApplications/Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
/myapp/myapp.csproj : warning NU1503: Skipping restore for project '/myapp/myapp.csproj'. The project file may be invalid or missing targets required for restore. [/myapp.sln]
/usr/share/dotnet/sdk/2.1.4/NuGet.targets(103,5): warning : Unable to find a project to restore! [/myapp.sln]
/myapp/myapp.csproj(582,3): error MSB4019: The imported project "/usr/share/dotnet/sdk/2.1.4/Microsoft/VisualStudio/v15.0/WebApplications/Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
script returned exit code 1
Dockerfile:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /
# Copy csproj and restore as distinct layers
COPY *.sln ./
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 /
COPY --from=build-env /out .
ENTRYPOINT ["dotnet", "myApp.dll"]
答案 0 :(得分:2)
从日志中看,您似乎正在构建一个ASP.NET MVC应用程序,而不是一个不支持dotnet cli的ASP.NET核心应用程序。
关注有关将非核心ASP.NET应用程序停靠的指南(某些指南称之为&#34;旧版ASP.NET应用程序&#34;),例如https://docs.microsoft.com/en-us/aspnet/mvc/overview/deployment/docker-aspnetmvc