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

时间:2019-12-10 17:46:27

标签: c# .net asp.net-core .net-core .net-core-3.0

我有一个使用.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>

我的课:

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

生成错误消息:

  

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

由于IApplicationBuilderExtensions是在Microsoft.AspNetCore.Builder命名空间中定义的,所以我不知道为什么它没有运行。如果我尝试运行,则相同的代码可以正常运行

1 个答案:

答案 0 :(得分:0)

尝试一下;

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

    return app;
}