我遵循本指南将.NET Core3.0应用程序部署到AWS:
https://aws.amazon.com/blogs/developer/net-core-3-0-on-lambda-with-aws-lambdas-custom-runtime/
我的serverless.template和article defaults.json文件是本文的副本。
我的应用程序是一个ASP.NET核心应用程序,它的目标框架是netcoreapp3.0,使用Amazon.Lambda.AspNetCoreServer和Amazon.Lambda.RuntimeSupport包。
当我运行dotnet lambda deploy-serverless时,会得到以下错误:
NETSDK1031:不指定RuntimeIdentifier,就不支持构建或发布自包含的应用程序。请指定一个RuntimeIdentifier或将SelfContained设置为false。
我看到的每个示例都为msbuild参数显示了这一点:
"msbuild-parameters": "--self-contained true /p:AssemblyName=bootstrap"
但是很明显,我可以从命令行尝试dotnet publish --self-contained true命令,并得到相同的错误(NETSDK1031)。这是怎么回事?
如果更改命令并运行dotnet publish --self-contained true -f netcoreapp3.0 -r linux-x64,它将在本地成功发布。
如果我用相同的必需参数更新msbulid参数并运行dotnet lambda deploy-serverless,则得到:
...发布: MSBUILD : error MSB1009: Project文件不存在。
我遗漏了什么?
发布于 2019-12-12 18:48:24
在深入研究工具的源代码之后,这里是:https://github.com/aws/aws-extensions-for-dotnet-cli/blob/6b3c0eaf04bb62995ca1c5dd71b0db7e564e8b74/src/Amazon.Lambda.Tools/LambdaDotNetCLIWrapper.cs)
我找到了构建dotnet发布命令的以下代码:
// If you set the runtime to RUNTIME_HIERARCHY_STARTING_POINT it will trim out the Windows and Mac OS specific dependencies but Razor view precompilation
// will not run. So only do this packaging optimization if there are no Razor views.
if (Directory.GetFiles(fullProjectLocation, "*.cshtml", SearchOption.AllDirectories).Length == 0)
{
arguments.Append($" -r {LambdaConstants.RUNTIME_HIERARCHY_STARTING_POINT}");
if (msbuildParameters == null ||
msbuildParameters.IndexOf("--self-contained", StringComparison.InvariantCultureIgnoreCase) == -1)
{
arguments.Append(" --self-contained false ");
}
if (string.IsNullOrEmpty(msbuildParameters) ||
!msbuildParameters.Contains("PreserveCompilationContext"))
{
_logger?.WriteLine("... Disabling compilation context to reduce package size. If compilation context is needed pass in the \"/p:PreserveCompilationContext=false\" switch.");
arguments.Append(" /p:PreserveCompilationContext=false");
}
}我的网站确实包括一个CSHTML,因为它是一个完整的网页应用程序。将以下参数添加到msbuild参数可以解决这个问题:-r rhel.7.2-x64
但是AWS并不意味着要处理完整的堆栈应用程序,静态文件也不能正常工作,所以最好的办法是分解应用程序,使Asp.Net核心Lambda项目仅仅是一个纯API。
发布于 2020-02-05 21:28:33
我也有同样的问题,我把/p:AssemblyName=bootstrap移到我的.csproj文件中。见附图。

https://stackoverflow.com/questions/59290414
复制相似问题