Search code examples
dockerasp.net-coreasp.net-core-2.1

ASP.NET Core application suddenly needs new specific version without changes


I have a ASP.NET Core application running in a Docker container (2.1-aspnetcore-runtime).

The docker container with the application ran without any problems for two months. Recently I had to update a ConnectionString in the AppSettings. So I changed the JSON file and deployed a new docker version.

This resulted in the following message:

It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.1.6' 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:
      http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
  - The .NET Core framework and SDK can be installed from:
      https://aka.ms/dotnet-download
  - The following versions are installed:
      2.1.4 at [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]

Why does the application suddenly need the version "2.1.6"? The application didn't change and two months ago the version "2.1.6" didn't even exist.

Besides this there is a specific Docker container for "2.1.6" (2.1.6-aspnetcore-runtime). Why isn't the newest version available in the normal "2.1-aspnetcore-runtime" container?


Solution

  • Why does the application suddenly need the version "2.1.6"? The application didn't change and two months ago the version "2.1.6" didn't even exist.

    This one is easy to explain. The newer, ASP.NET Core 2.1 (and later) templates are generated with implicit versioning for Microsoft.AspNetCore.All/Microsofot.AspNetCore.App packages.

    In ASP.NET Core 2.1 or later, you can specify the Microsoft.AspNetCore.All package reference without a version. When the version isn't specified, an implicit version is specified by the SDK (Microsoft.NET.Sdk.Web). We recommend relying on the implicit version specified by the SDK and not explicitly setting the version number on the package reference. If you have questions about this approach, leave a GitHub comment at the Discussion for the Microsoft.AspNetCore.App implicit version.

    Your entries in csproj will then just look like

    <PackageReference Include="Microsoft.AspNetCore.All" />
    

    instead of

    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.4" />
    

    This makes sure that every rebuild will use/pick up the latest minor packages available on the system. That applies for portable apps. Self-contained basically do the same, but with the runtime available at the publishing time.

    That is whats causing the issue for you in the first place.

    Why isn't the newest version available in the normal "2.1-aspnetcore-runtime" container?

    You probably didn't run docker pull microsoft/dotnet:2.1-aspnetcore-runtime before creating/building (or running) your docker container.

    When you don't do that, it will use the latest locally tagged version (but not the latest version available for that tag on docker hub), because the microsoft/dotnet:2.1-aspnetcore-runtime will point to a newer minor versions when they come out, but this requires you to do a new pull to get the most recent version for the (re)tagged image.