错误 CS1061:“IServiceCollection”不包含“AddApplicationInsightsTelemetry”的定义

问题描述 投票:0回答:1

我按照此链接为 ASP.NET Core 应用程序设置 Application Insights

我能够在本地进行构建,但是当我尝试在我的天蓝色管道中运行构建时,它失败并给出以下错误:- 这是我的代码:-

public void ConfigureServices(IServiceCollection services)
    {
        string[]? initialScopes = Configuration.GetValue<string>("DownstreamApi:Scopes")?.Split(' ');
        

        services.AddHttpContextAccessor();

        var sqlConnectionString = Configuration.GetConnectionString("DatabaseConnection");
        services.AddDbContext<PostgreSQLContext>(options => options.UseNpgsql(sqlConnectionString));

        services.AddAutoMapper(typeof(Startup));
        services.AddSingleton(Configuration);
        services.AddSingleton<IWebHostEnvironment>(_webHostEnvironment);
        services.AddControllers(options =>
        {
            options.ModelMetadataDetailsProviders.Add(new SystemTextJsonValidationMetadataProvider());
        });

        services.AddTransient<CustomJwtBearerHandler>();
        services.AddHttpClient();
        services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddScheme<JwtBearerOptions, CustomJwtBearerHandler>(JwtBearerDefaults.AuthenticationScheme, options => { });
        
        services.AddApplicationInsightsTelemetry();
        services.AddMvc(options =>
        {
            options.MaxModelValidationErrors = 50;
            options.ModelBindingMessageProvider.SetValueMustNotBeNullAccessor(
                _ => "The field is required.");
        });}
c# asp.net azure-devops azure-application-insights azure-monitoring
1个回答
0
投票

我可以在 Azure DevOps 中重现类似的问题。

格式:

services.AddApplicationInsightsTelemetry();
适用于 ASP.NET Core 5 或更早版本。

默认情况下,如果您使用 Microsoft 托管代理,它将使用 .net7 或 .net8。

您可以尝试添加任务:使用.NET Core设置与本地机器相同的.net core版本。

例如:

另一方面,您也可以尝试在您的

.cs
文件中进行以下更改。

更改自:

services.AddApplicationInsightsTelemetry();

services.AddApplicationInsightsTelemetryWorkerService();
© www.soinside.com 2019 - 2024. All rights reserved.