"Type or namespace does not exist" 将 C# 函数发布到 AWS lambda 时出错

"Type or namespace does not exist" error when publishing a C# function to AWS lambda

我已经成功部署了一层包,现在正尝试使用应用程序发布我的函数。

存储的 S3 存储桶中的工件文件:

<?xml version="1.0"?>

-<StoreArtifacts>

<Package Version="2.0.0" Id="Amazon.Lambda.Core"/>

<Package Version="1.2.0" Id="Amazon.Lambda.Core"/>

<Package Version="2.1.0" Id="Amazon.Lambda.Serialization.SystemTextJson"/>

<Package Version="1.8.0" Id="DocX"/>

<Package Version="1.18.0" Id="Azure.Core"/>

<Package Version="1.0.0" Id="Microsoft.Bcl.AsyncInterfaces"/>

<Package Version="4.6.0" Id="Microsoft.Graph"/>

<Package Version="2.0.5" Id="Microsoft.Graph.Core"/>

<Package Version="4.35.1" Id="Microsoft.Identity.Client"/>

<Package Version="6.12.2" Id="Microsoft.IdentityModel.JsonWebTokens"/>

<Package Version="6.12.2" Id="Microsoft.IdentityModel.Logging"/>

<Package Version="6.12.2" Id="Microsoft.IdentityModel.Protocols"/>

<Package Version="6.12.2" Id="Microsoft.IdentityModel.Protocols.OpenIdConnect"/>

<Package Version="6.12.2" Id="Microsoft.IdentityModel.Tokens"/>

<Package Version="6.12.2" Id="System.IdentityModel.Tokens.Jwt"/>

<Package Version="1.0.2" Id="System.Memory.Data"/>

<Package Version="13.0.1" Id="Newtonsoft.Json"/>

</StoreArtifacts>

然后我尝试使用以下方法部署函数:

dotnet lambda deploy-function DemoFunction --function-layers arn:aws:lambda:us-east-2:687758306845:layer:DemoLayer:1

我收到多个错误

... publish: C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\Function.cs(4,7): error CS0246: The type or namespace name 'Xceed' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\DemoTests.csproj]
... publish: C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\Function.cs(5,7): error CS0246: The type or namespace name 'Xceed' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\DemoTests.csproj]
... publish: C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\Function.cs(8,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\DemoTests.csproj]
... publish: C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\Function.cs(10,17): error CS0234: The type or namespace name 'Identity' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\DemoTests.csproj]
... publish: C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\Function.cs(11,17): error CS0234: The type or namespace name 'Graph' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\DemoTests.csproj]

我怎样才能让这个部署工作?失败的行在顶部的导入处:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xceed.Document.NET;
using Xceed.Words.NET;
using Amazon.Lambda.Core;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using Microsoft.Identity.Client;
using Microsoft.Graph;
using System.Net.Http.Headers;

您确定您的测试以及您的项目引用了所需的包吗?

根据您的错误消息,DemoTests.csproj 似乎缺少引用:

[C:\Users\UserX\source\repos\DemoTests\DemoTests\src\DemoTests\DemoTests.csproj]