7

I have a small .NET Framework 4.6.2 application with a few NuGet package references. On executing: docker build -t myapp . I receive the error: Could not resolve this reference. for each of the referenced NuGet packages.

I have tried:

  • Adding RUN ["dotnet", "restore"] to restore the packages from the .csproj
  • Changing the image tag to :4.6.2

How do I add the NuGet packages to the build proces?

Thanks for your time!

Dockerfile:

FROM microsoft/dotnet-framework-build:4.7.1 as build-env

WORKDIR /app
COPY . /app

RUN ["dotnet", "build"]

FROM microsoft/dotnet-framework:4.7.1
WORKDIR /app
COPY --from=build-env /app .

ENTRYPOINT ["MessageProcessor.exe"]

Full error for a single reference from the Build step:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2041,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "GreenPipes, Version=1.2.1.98, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\app\MessageProcessor.csproj]
Wijnand
  • 1,192
  • 4
  • 16
  • 28
  • in my case i only have ```RUN dotnet restore``` and it works. are you in the right folder when you run ```COPY . .``` ? What was your output from dotnet restore – Boas Enkler Feb 06 '18 at 12:36
  • Edited the COPY line. When I add `RUN dotnet restore` I get the output: `Restore: Nothing to do. None of the projects specified contain packages to restore. Done Building Project "C:\app\MessageProcessor.csproj" (Restore target(s)).` – Wijnand Feb 06 '18 at 12:49
  • Forgive me my ignorance, but is not this .NET core and not full .NET framework and hence dotnet is not used to build the projects? – Gregory Suvalian Feb 06 '18 at 13:36
  • @GregorySuvalian The app is based on a .NET Framework 4.6.2 based project. I wish using .NET Core was an option... – Wijnand Feb 06 '18 at 13:40

1 Answers1

15

Figured it out.

MSBuild (RUN ["dotnet", "restore"]) doesn't restore the NuGet packages for some reasons explained here. So I started playing around with nuget.exe commands and that worked eventually.

FROM microsoft/dotnet-framework-build:4.7.1 as build-env

WORKDIR /app
COPY . /app
RUN nuget.exe restore MessageProcessor.csproj -SolutionDirectory ../ -Verbosity normal
RUN MSBuild.exe MessageProcessor.csproj /t:build /p:Configuration=Release /p:OutputPath=./out

FROM microsoft/dotnet-framework:4.7.1
WORKDIR /app
COPY --from=build-env app/out .

ENTRYPOINT ["MessageProcessor.exe"]

This leaves me a nice clean and shiny .NET Framework 4.6.2 Docker container.

Wijnand
  • 1,192
  • 4
  • 16
  • 28
  • For those who stumbled upon the answer. `dotnet restore` is CLI utility for `.NET Core`, not `.NET Framework` that's why you need to use `.NET Framework` utilities like `nuget.exe` or `MSBuild.exe` – Adilet Soronov Mar 03 '23 at 02:52