【发布时间】:2020-04-20 20:47:28
【问题描述】:
我正在尝试打包一个 .net 核心 lambda 函数,其中包含对 .net 标准 2.0 类库的引用。
使用 AWS Lambda 工具包在本地发布和运行工作正常。但是,当我尝试部署到 AWS 时,打包失败并出现以下错误。
我尝试将我的 lambda 函数用于 .net core 2.1 和 3.1,但结果相同。
有什么想法吗?
$ dotnet lambda package
Amazon Lambda Tools for .NET Core applications (3.3.1)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet
Executing publish command
Deleted previous publish folder
... invoking 'dotnet publish', working folder 'C:\Users\andre\source\repos\awslambda3\bin\Release\netcoreapp2.1\publish'
... Disabling compilation context to reduce package size. If compilation context is needed pass in the "/p:PreserveCompilationContext=false" switch.
... publish: Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
... publish: Copyright (C) Microsoft Corporation. All rights reserved.
... publish: Restore completed in 53.2 ms for C:\Users\andre\source\repos\LambdaModels\LambdaModels.csproj.
... publish: Restore completed in 572.08 ms for C:\Users\andre\source\repos\awslambda3\AWSLambda3.csproj.
... publish: Restore completed in 573 ms for C:\Users\andre\source\repos\AWSLambda3.Tests\AWSLambda3.Tests.csproj.
... publish: C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1005: Assets file 'C:\Users\andre\source\repos\LambdaModels\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.1'. Ensure that restore has run and that you have included 'netcoreapp2.1' in the TargetFrameworks for your project. [C:\Users\andre\source\repos\LambdaModels\LambdaModels.csproj]
... publish: LambdaModels -> C:\Users\andre\source\repos\LambdaModels\bin\Release\netstandard2.0\LambdaModels.dll
... publish: AWSLambda3 -> C:\Users\andre\source\repos\AWSLambda3\bin\Release\netcoreapp2.1\AWSLambda3.dll
... publish: AWSLambda3.Tests -> C:\Users\andre\source\repos\AWSLambda3.Tests\bin\Release\netcoreapp2.1\rhel.7.2-x64\AWSLambda3.Tests.dll
... publish: AWSLambda3.Tests -> C:\Users\andre\source\repos\awslambda3\bin\Release\netcoreapp2.1\publish\
... publish: AWSLambda3 -> C:\Users\andre\source\repos\awslambda3\bin\Release\netcoreapp2.1\rhel.7.2-x64\AWSLambda3.dll
... publish: AWSLambda3 -> C:\Users\andre\source\repos\awslambda3\bin\Release\netcoreapp2.1\publish\
Failed to create application package
【问题讨论】:
-
这是您的实际错误:
project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.1' -
解决办法是什么?我发现的唯一解决方案是我必须在 .net 标准 csproj 的 targetframeworks 元素中添加 netcoreapp。但我不认为这是合适的。当您将 .net 标准类库与 .net 核心控制台或其他一些项目类型一起使用时,您不必这样做。此外,如果您没有 .net 标准的源代码,则无法重新编译目标 .netcoreapp。我追求的解决方案只会影响我控制的 lambda 函数项目,而不是引用的项目。谢谢。
标签: amazon-web-services .net-core aws-lambda .net-standard