简体   繁体   中英

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM