“IHostingEnvironment"已过时 [英] 'IHostingEnvironment' is obsolete

查看:55
本文介绍了“IHostingEnvironment"已过时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的 ASP.NET Core 项目更新为 .NET Core v3.0.0-preview3,我现在得到:

I updated my ASP.NET Core project to .NET Core v3.0.0-preview3, and I now get:

Startup.cs(75,50,75,69):警告 CS0618:IHostingEnvironment"是obsolete: '此类型已过时,将来会被删除版本.推荐的替代方案是Microsoft.AspNetCore.Hosting.IWebHostEnvironment.'

Startup.cs(75,50,75,69): warning CS0618: 'IHostingEnvironment' is obsolete: 'This type is obsolete and will be removed in a future version. The recommended alternative is Microsoft.AspNetCore.Hosting.IWebHostEnvironment.'

代码是:

public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
  if (env.IsDevelopment()) {
    …
  }
}

现在这样做的正确方法是什么?是否有任何文档或示例可以证明这一点?

What is the correct way to do this now? Are there any documentation or examples to demonstrate that?

推荐答案

看来 IHostingEnvironment 已被 IHostEnvironment(以及其他一些)取代.您应该能够更改代码中的接口类型,一切都会像以前一样工作:-)

It seems IHostingEnvironment has been replaced by IHostEnvironment (and a few others). You should be able to change the interface type in your code and everything will work as it used to :-)

您可以在 GitHub 上的此链接中找到有关更改的更多信息https://github.com/aspnet/AspNetCore/issues/7749

You can find more information about the changes at this link on GitHub https://github.com/aspnet/AspNetCore/issues/7749

编辑还有一个额外的接口 IWebHostEnvironment 可以在 ASP.NET Core 应用程序中使用.这在 Microsoft.AspNetCore.Hosting 命名空间中可用.

EDIT There is also an additional interface IWebHostEnvironment that can be used in ASP.NET Core applications. This is available in the Microsoft.AspNetCore.Hosting namespace.

这篇关于“IHostingEnvironment"已过时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆