简体   繁体   中英

error CS0246: The type or namespace name 'IApplicationBuilderExtensions' could not be found

I have a library project using .NET Core 3.0, but I can't use the "IApplicationBuilderExtensions" interface.

My csproj :

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

</Project>

My class:

using System;
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.Hosting;
using Microsoft.Extensions.Logging;

namespace MyExtensions
{
    public static class IApplicationBuilderExtension
    {
        public static IApplicationBuilderExtensions Configure(this IApplicationBuilderExtensions app)
        {
            app.UseHsts();
            app.UseHttpsRedirection(); 
            app.UseRouting();
            // more...

            return app;
        }
    }
}

Build error message:

error CS0246: The type or namespace name 'IApplicationBuilderExtensions' could not be found

As IApplicationBuilderExtensions is defined inside the Microsoft.AspNetCore.Builder namespace, I don't know why it is not running. Same code runs fine if I try to run

Try this;

public static IApplicationBuilder Configure(this IApplicationBuilder app)
{
    app.UseHsts();
    app.UseHttpsRedirection(); 
    app.UseRouting();
    // more...

    return app;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM