'IServiceCollection' 不包含 'AddAWSService' 的定义,并且在 asp.net core 2.2 中没有可访问的扩展方法 'AddAWSService' 错误?

Fah*_*san 4 c# amazon-sqs amazon-web-services asp.net-core

Aws SQS我正在项目中设置asp.net core 2.22。我正在我的文件中添加 aws 配置行Program.cs。这是我的Program.cs文件。

using Amazon.SQS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace analytics
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; set;}

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddCors(c =>
            {
                c.AddPolicy("AllowOrigin", options =>
                {
                    options.AllowAnyOrigin();
                });
            });


             // AWS Configuration
                    var awsoptions = Configuration.GetAWSOptions();
                    services.AddDefaultAWSOptions(awsoptions);
                    services.AddAWSService<IAmazonSQS>();

                    // Worker Service
                    // services.AddHostedService<Worker>();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            // app.UseHttpsRedirection();
            app.UseMvc();
            app.UseCors(options =>
            {
                options.AllowAnyOrigin();
            });
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我在控制台上收到这些错误

Startup.cs(40,52): error CS1061: 'IConfiguration' does not contain a definition for 'GetAWSOptions' 
and no accessible extension method 'GetAWSOptions' accepting a first argument of type 
'IConfiguration' could be found (are you missing a using directive or an assembly reference?) 
[D:\OfficeProjects\beelinksanalytics\analytics.csproj]

Startup.cs(41,30): error CS1061: 'IServiceCollection' does not contain a definition for 
'AddDefaultAWSOptions' and no accessible extension method 'AddDefaultAWSOptions' accepting a first 
argument of type 'IServiceCollection' could be found (are you missing a using directive or an 
assembly reference?) [D:\OfficeProjects\beelinksanalytics\analytics.csproj]

Startup.cs(42,30): error CS1061: 'IServiceCollection' does not contain a definition for 
'AddAWSService' and no accessible extension method 'AddAWSService' accepting a first argument of 
type 'IServiceCollection' could be found (are you missing a using directive or an assembly 
reference?) [D:\OfficeProjects\beelinksanalytics\analytics.csproj]
Run Code Online (Sandbox Code Playgroud)

基本上我想实现Aws SQS服务来侦听队列消息并希望根据这些消息执行一些操作。所以我正在努力配置Aws Sdkaws sqs项目asp.net core 2.2

我没有找到任何关于如何aws sqs在asp.net core 2.2中配置的相关文档。请告诉我这有什么问题吗?

Lui*_*oza 9

只需在命令行中运行此命令,如@panagiotis-kanavos中提到的那样(在此处选择您想要的版本)

dotnet 添加包 AWSSDK.Extensions.NETCore.Setup --版本 3.3.101

验证引用是否已添加到您的 .csproj 中

在此输入图像描述

这对我有用,我希望对你也有用