错误 CS0246:找不到类型或命名空间名称 'IApplicationBuilderExtensions'

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

我有一个使用 .NET Core 3.0 的库项目,但我无法使用 "IApplicationBuilderExtensions" 接口。

我的csproj:

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

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

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

</Project>

我的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;
        }
    }
}

生成错误信息:

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

由于IApplicationBuilderExtensions定义在Microsoft.AspNetCore.Builder命名空间内,不知道为什么不是运行ning。如果我尝试 运行

,相同的代码 运行 没问题

试试这个;

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

    return app;
}