Solution: The Framework 'Microsoft.NETCore.App', Version '2.1.0' Was Not Found

Scenario & Error

Is Microsoft going to end support for the Web API developed using .Net Core 2.1by Aug 21? We planned to migrate it to .Net Core 3.1 and successfully migrated it. We were able to run the application in the local machine using Visual Studio IDE and manually package uploading in AWS Lambda, which  worked well. But the automation build & deployment are getting failed with the below error,

It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
The following frameworks were found:
3.1.15 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Fix applied

  1. .NET code does not contain any error. All migration code was done well.
  2. The root cause of the issue lies in the Circle CI configuration file (YAML).
  3. At step “Install Serverless CLI” build pipeline run the below command,

    dotnet tool install --global Amazon.Lambda.Tools --version 3.1
     
  4. The command installs the Tool 'amazon.lambda.tools' (version '3.1.0')
  5. However, this version of Amazon.Lambda.Tools have a strong dependency on .NETCoreApp 2.1. see below screenshot

The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.

So, at a later step, when the command “dotnet lambda package --configuration release --framework netcoreapp3.1 --output-package bin/release/netcoreapp3.1/deploy-package.zip” is run, the AWS tool is unable to complete the command as it could not find the missing dependency of NETCoreApp 2.1.

As we are upgrading the code from .NET core 2.1 to .NET core 3.1, we cannot downgrade to NETCoreApp 2.1. Finally, after changing the command to “dotnet tool install --global Amazon.Lambda.Tools”, which makes sure the latest version (5.1.2) is installed. This version of the Amazon.Lambda.Tools package has no dependencies and deployment goes smooth fixing the problem.

The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.

Yaml File snap for ref

Before Fix

The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.

The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.

After Fix

The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.