简体   繁体   English

dotnet-core 默认为 2.0 框架 ubuntu

[英]Dotnet-core defaulting to 2.0 framework ubuntu

I am intergrating a c# project to use AWS codebuild with a ubuntu linux OS.我正在集成 c# 项目,以将 AWS 代码构建与 ubuntu linux 操作系统结合使用。 All target frameworks are 3.1.所有目标框架都是 3.1。 For some reason when running this on AWS codebuild it looks for 2.0?出于某种原因,在 AWS codebuild 上运行它时,它会寻找 2.0? When following the link it throws to resolve the error Microsoft clearly states to use 3.1当点击链接时,它抛出解决微软明确声明使用 3.1 的错误

I have tried to use TargetFramework and RuntimeFrameWork in.csproj <TargetFramework>netcoreapp3.1</TargetFramework> <RuntimeFrameworkVersion>3.0.*</RuntimeFrameworkVersion>我尝试在.csproj <TargetFramework>netcoreapp3.1</TargetFramework> <RuntimeFrameworkVersion>3.0.*</RuntimeFrameworkVersion>中使用TargetFrameworkRuntimeFrameWork

As well I have even created a global.json我什至还创建了一个 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?为什么它继续尝试用 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.我在 Mac 上使用 Visual Studio 代码,并在我的 Mac 上使用相同的构建命令,在 3.1 中正确构建,没有抛出错误。

For anyone else that may encounter this error.对于可能遇到此错误的其他任何人。 So digging around, I found a blog post by AWS.于是四处挖掘,我发现了 AWS 的一篇博文。

In the.csproj file of your project there is a reference to:在您项目的 .csproj 文件中,有对以下内容的引用:

<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.从 dotnet 2.1 开始,AWS 现在已转向全局工具,不再支持 cli 引用。

So they advise you to remove the DotNetCliToolReference line in.csproj and install the tools globally from nuget.因此,他们建议您删除.csproj 中的DotNetCliToolReference行并从 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.如果您使用的是 dotnet 3.1 并在 .csproj 中有该引用并使用 linux / codebuild 它将自动使用该引用而不是可能安装的任何全局引用。

So removing this line and then in buildspec.yml using the command to install the Amazon.Lambda.Tools nuget package, will resolve the error.所以删除这一行,然后在 buildspec.yml 中使用命令安装Amazon.Lambda.Tools nuget package,将解决错误。

This is the AWS blog post explaining these changes.这是解释这些更改的 AWS 博客文章。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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