Jay Shri
Jay Shri

Reputation: 119

Cannot Build .Net Core MVC solution suing Dockerfile: Project not found, missing targets, invalid project

I am trying to build a .NET core MVC project in a Docker container via Jenkins. I have set up the pipeline to pull from git and build inside a Docker container, but I keep getting these errors when I try to build my solutions.

I got the Dockerfile from https://docs.docker.com/engine/examples/dotnetcore/#create-a-dockerfile-for-an-aspnet-core-application and changed it appropriately for my project. It is placed inside the project directory in the same folder as my .sln file. For some reason, it's failing. My file structure seems to be right, but the script cannot seem to find my project or the build tools inside the imported environment.

Error text (Jenkins)

[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"]

Upvotes: 2

Views: 2021

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100543

From the logs, it looks like you are building an ASP.NET MVC application, not an ASP.NET Core application, which is not supported by the dotnet cli.

Follow guides about dockerizing non-core ASP.NET applications (some guides call this a "legacy ASP.NET application") like https://learn.microsoft.com/en-us/aspnet/mvc/overview/deployment/docker-aspnetmvc

Upvotes: 4

Related Questions