2017-03-17 82 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,並且!