Dotnet-core defaulting to 2.0 framework ubuntu

I am intergrating a c# project to use AWS codebuild with a ubuntu linux OS. All target frameworks are 3.1. For some reason when running this on AWS codebuild it looks for 2.0? When following the link it throws to resolve the error Microsoft clearly states to use 3.1

I have tried to use TargetFramework and RuntimeFrameWork in .csproj
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeFrameworkVersion>3.0.*</RuntimeFrameworkVersion>

As well I have even created a global.json

   {
       "sdk": {
        "version": "3.1.5",
        "rollForward": "latestFeature"
     }
    }

My command to build is

dotnet restore
dotnet lambda package --configuration release --framework netcoreapp3.1 --output-package bin/release/netcoreapp3.1/foo-bar.zip

The error I get continues to be:

The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
  - The following frameworks were found:
      3.1.5 at [/root/.dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=ubuntu.18.04-x64

Why does it continue to try to build with dotnet core 2.0? I am using visual studio code on a mac and using the same build command on my mac build correctly in 3.1 with no errors thrown.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

For anyone else that may encounter this error. So digging around, I found a blog post by AWS.

In the .csproj file of your project there is a reference to:

<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.2.0" />

AWS has now moved to global tools and no longer supporting cli reference, starting with dotnet 2.1.

So they advise you to remove the DotNetCliToolReference line in .csproj and install the tools globally from nuget. You no longer need to reference them as they will now be global.

If you are using dotnet 3.1 and have that reference in the .csproj and use linux / codebuild it will automatically use that reference instead of anything global that may be installed.

So removing this line and then in buildspec.yml using the command to install the Amazon.Lambda.Tools nuget package, will resolve the error.

This is the AWS blog post explaining these changes.

https://aws.amazon.com/blogs/developer/net-core-global-tools-for-aws/


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x