2017-03-17 16 views
1

我正在编写C#(.NET Core)中的Alexa技能,以便从AWS Lambda函数(运行在Amazon Linux上)运行。当我编译项目(的dotnet发布),我得到的错误:AWS Lambda和.NET Core - 使用Linux运行时?

Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win10- x64, win81-x64, win8-x64, win7-x64'. Possible causes:

  1. The project has not been restored or restore failed - run dotnet restore
  2. The project does not list one of 'win10-x64, win81-x64, win8-x64, win7-x64' in the 'runtimes' section.
  3. You may be trying to publish a library, which is not supported. Use dotnet pack to distribute libraries.

如果我指定Windows运行时(如win10-64),它将编译正常,但是我的一个依赖(Google Sheets API)由于在基于Linux的Lambda上而在运行时遇到问题。使用Linux运行时(如debian.8-x64)将导致相同的编译错误。

为什么AWS SDK在自己的平台是Linux时需要Windows运行时?我觉得我错过了一些明显的东西,并且在有人将问题指给我看的时候,我会很高兴地面对掌心。

我project.json文件(主要应用和.NET核心类库项目):

AlexaProj

{ 
    "version": "1.0.0-*", 
    "buildOptions": { 
    }, 

    "dependencies": { 
    "Microsoft.NETCore.App": "1.1.1", 
    "Amazon.Lambda.Core": "1.0.0*", 
    "Amazon.Lambda.Serialization.Json": "1.0.1", 
    "Amazon.Lambda.Tools": { 
     "type": "build", 
     "version": "1.3.0-preview1" 
    }, 
    "Slight.Alexa.Core": "1.0.10-beta", 
    "AlexaProjLib": "1.0.0-*" 
    }, 

    "tools": { 
    "Amazon.Lambda.Tools": "1.3.0-preview1" 
    }, 

    "runtimes": { 
    "win10-x64": { } <--- Compiles, but fails at runtime 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": "dnxcore50" 
    } 
    } 
} 

AlexaProjLib

{ 
    "version": "1.0.0-*", 

    "dependencies": { 
    "Google.Apis": "1.21.0", 
    "Google.Apis.Core": "1.21.0", 
    "Google.Apis.Oauth2.v2": "1.21.0.672", 
    "Google.Apis.Sheets.v4": "1.21.0.798", 
    "NETStandard.Library": "1.6.1" 
    }, 

    "frameworks": { 
    "netstandard1.6": { 
     "imports": "dnxcore50" 
    } 
    } 
} 

回答

2

我发现JeffRCorp posted on the AWS forums about having a similar issue,他们的步骤也为我工作。

首先我编辑project.json和移动Microsoft.NETCore.App依赖到框架部分(虽然我不知道这是否有差别)。我还删除了运行时间段部分。最后project.json:

{ 
    "version": "1.0.0-*", 
    "buildOptions": { 
    }, 

    "dependencies": { 
    "Amazon.Lambda.Core": "1.0.0*", 
    "Amazon.Lambda.Serialization.Json": "1.0.1", 
    "Amazon.Lambda.Tools": { 
     "type": "build", 
     "version": "1.3.0-preview1" 
    }, 
    "Slight.Alexa.Core": "1.0.10-beta", 
    "AlexaProjLib": "1.0.0-*" 
    }, 

    "tools": { 
    "Amazon.Lambda.Tools": "1.3.0-preview1" 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": "dnxcore50", 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.1.1" 
     } 
     } 
    } 
    } 
} 

我然后跑DOTNET拉姆达包它内置的.zip文件中斌/发行/ netcoreapp1.0目录。通过AWS控制台将其上传到AWS Lambda,并且!