简体   繁体   English

错误 CS0246:找不到类型或命名空间名称“IWebHostEnvironment”(您是否缺少 using 指令或程序集引用?)

[英]error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?)

I am trying to run a docker build for a .net app, the source code is here : https://github.com/NileshGule/AKS-learning-series/tree/master/src我正在尝试为 .net 应用程序运行 docker build,源代码在这里: https : //github.com/NileshGule/AKS-learning-series/tree/master/src

After following the steps I get the error:按照步骤操作后,我收到错误消息:

Web/Startup.cs(30,56): error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) [/TechTalksWeb/TechTalksWeb.csproj]

I believe this has been deprecated in .Net 3.0 but I am on .Net 2.1我相信这在 .Net 3.0 中已被弃用,但我在 .Net 2.1

dotnet --version                                                       
2.1.607

The full output of the build below下面构建的完整输出

➜  TechTalksWeb git:(master) ✗ docker build .                                                                                                     
Sending build context to Docker daemon  6.879MB
Step 1/11 : FROM microsoft/dotnet:2.1.300-sdk  AS build-env
 ---> 90a5a2ee9755
Step 2/11 : WORKDIR /TechTalksWeb
 ---> Running in bf2efd408659
Removing intermediate container bf2efd408659
 ---> b5c1c0a8f026
Step 3/11 : COPY NuGet.config ./
 ---> 2fbe7f9eb0ba
Step 4/11 : COPY TechTalksWeb.csproj ./
 ---> 49e1c29e4144
Step 5/11 : RUN dotnet restore
 ---> Running in bfb23ac61bbf
  Restoring packages for /TechTalksWeb/TechTalksWeb.csproj...
  Generating MSBuild file /TechTalksWeb/obj/TechTalksWeb.csproj.nuget.g.props.
  Generating MSBuild file /TechTalksWeb/obj/TechTalksWeb.csproj.nuget.g.targets.
  Restore completed in 1.4 sec for /TechTalksWeb/TechTalksWeb.csproj.
Removing intermediate container bfb23ac61bbf
 ---> 2b5068160dd8
Step 6/11 : COPY . ./
 ---> d6e2551f5bfb
Step 7/11 : RUN dotnet publish --configuration Release --output releaseOutput --no-restore
 ---> Running in f08fbc49c68f
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Web/Startup.cs(30,56): error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) [/TechTalksWeb/TechTalksWeb.csproj]
The command '/bin/sh -c dotnet publish --configuration Release --output releaseOutput --no-restore' returned a non-zero code: 1

The line in question is part of startup.cs有问题的行是 startup.cs 的一部分

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

Full code below:完整代码如下:

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.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

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

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // 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.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

As far as I can remember well it's called IWebHostEnvironment is used in .NET Core 3.0.据我所知,它被称为IWebHostEnvironment ,用于 .NET Core 3.0。

In .NET Core 2.1 you need to use IHostingEnvironment (that has been deprecated in 3.0).在 .NET Core 2.1 中,您需要使用IHostingEnvironment (在 3.0 中已弃用)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 CS0246:找不到类型或命名空间名称“Npgsql”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?) 错误CS0246找不到类型或名称空间名称“ Windows”(是否缺少using指令或程序集引用?) - Error CS0246 The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“StreamingContext”(是否缺少 using 指令或程序集引用?) - Error CS0246: The type or namespace name 'StreamingContext' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246 找不到类型或命名空间名称“CreateRandomAnswersForKey”(您是否缺少 using 指令或程序集引用?)? - Error CS0246 The type or namespace name 'CreateRandomAnswersForKey' could not be found (are you missing a using directive or an assembly reference?)? CS0246:找不到类型或命名空间名称'MySql'(您是否缺少using指令或程序集引用 - CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference CS0246:找不到类型或名称空间名称“ Employee”(您是否缺少using指令或程序集引用?)? - CS0246: The type or namespace name 'Employee' could not be found (are you missing a using directive or an assembly reference?)? CS0246 找不到类型或命名空间名称“ErrorViewModel”(您是否缺少 using 指令或程序集引用?) - CS0246 The type or namespace name 'ErrorViewModel' could not be found (are you missing a using directive or an assembly reference?) C# 错误:错误 CS0246 找不到类型或命名空间名称“”(您是否缺少 using 指令或程序集引用?) - C# Error: Error CS0246 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) C# 错误 CS0246 找不到类型或命名空间名称“Socket”(您是否缺少 using 指令或程序集引用) - C# error CS0246 The type or namespace name 'Socket' could not be found (are you missing a using directive or an assembly reference) 错误CS0246找不到类型或名称空间名称“ Write_To_Console_dr”(您是否缺少using指令或程序集引用 - Error CS0246 The type or namespace name 'Write_To_Console_dr' could not be found (are you missing a using directive or an assembly reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM