Reputation: 75416
I am currently experimenting with using JIB for packaging and deploying a dotnet project not written by me (I am not very familiar with dotnet).
I have the dotnet SDK installed (and visual studio 19) on my windows machine and after invoking "dotnet publish -c Release" on my solution which contain a project X and a test project X_test I end up with a bin/Release/netcoreapp2.1\publish folder.
In here I can run "dotnet X.dll" and the application starts.
Now I want to deploy said published folder to a docker image. My first attempt was using mcr.microsoft.com/dotnet/core/runtime:2.1
which caused
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.1.1' was not found.
- Check application dependencies and target a framework version installed at:
/usr/share/dotnet/
- Installing .NET Core prerequisites might help resolve this problem:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
I then tried using mcr.microsoft.com/dotnet/core/aspnet:2.1
which gave
C:\Users\m86194\git\microsvc-operational-information>docker run -it operational-information-ms:0.0.1-SNAPSHOT bash
Error:
An assembly specified in the application dependencies manifest (Operational_Information.deps.json) was not found:
package: 'Elasticsearch.Net', version: '6.0.0'
path: 'lib/netstandard1.3/Elasticsearch.Net.dll'
There is an "Elasticsearch.Net.dll" file in the root of bin\Release\netcoreapp21\publish
folder, but not elsewhere.
I believe there is something about the build process I am missing.
Suggestions?
Upvotes: 1
Views: 7245
Reputation: 12854
I had the same problem with Asp.Net Core 3 and since I'm neither well versed in Docker nor the .Net build system, I used the default Dockerfile Visual Studio creates.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Application/Application.csproj", "Application/"]
COPY ["Dependency1/Dependency1.csproj", "Dependency1/"]
RUN dotnet restore "Application/Application.csproj"
COPY . .
WORKDIR "/src/Application"
RUN dotnet build "Application.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Application.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "application.dll"]
By default it only runs dotnet restore
for the main application. After adding the same for the dependent projects, it works.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Application/Application.csproj", "Application/"]
COPY ["Dependency1/Dependency1.csproj", "Dependency1/"]
RUN dotnet restore "Dependency1/Dependency1.csproj" <-- this one is new
RUN dotnet restore "Application/Application.csproj"
COPY . .
WORKDIR "/src/Application"
RUN dotnet build "Application.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Application.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "application.dll"]
Upvotes: 1
Reputation: 75416
Turned out that I had made a mistake when specifying the docker file deployment.
Instead of using bin\Release\netcoreapp21\publish
I used bin\Release\netcoreapp21\
which also has an X.dll along the publish
folder but gave the error. Changing to use the publish
folder instead, solved the problem.
Upvotes: 0
Reputation: 301
Try doing a dotnet restore
before executing the publish command. Alternatively, you can use a multi stage docker build. See https://docs.docker.com/engine/examples/dotnetcore/ (mind the aspnet core version)
Upvotes: 1