找不到类型或名称空间名称"IWebHostEnvironment"(您是否缺少using指令或程序集引用?) [英] The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?)
问题描述
我正在使用.NET Core 3.0.100; Microsoft Visual Studio Community 2019预览版16.4.0预览版1.0; Blazor服务器(正式发行版).
I am using .NET Core 3.0.100 ; Microsoft Visual Studio Community 2019 Preview Version 16.4.0 Preview 1.0 ; Blazor-server (official release).
我正在尝试将身份验证和授权添加到我的Blazor服务器Web应用程序.我在这里阅读指南
I am trying to add Authentication and Authorization to my Blazor-server web app. I am reading guideline at here https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-3.0&tabs=visual-studio#scaffold-identity-into-an-empty-project
(我也阅读了此 https://github.com/aspnet/Identity/issues/1825 )
然后我右键单击Project,选择Add
\ New Scaffolded Item...
Then I right-click on Project, choose Add
\ New Scaffolded Item...
我阅读了文件ScaffoldingReadme.txt
,然后按照指南进行操作.
I read file ScaffoldingReadme.txt
, then follow the guide.
我按F5进行调试,发现错误
I press F5 for debugging, I catch error
Severity: Error
Error Code: CS0246
Description: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?)
Project: foo
File: C:\Users\donhuvy\Desktop\foo\bar\obj\Debug\netcoreapp3.0\Razor\Pages\Shared\_Layout.cshtml.g.cs
Line: 455
Suppression State: Active
屏幕截图 [![在此处输入图片描述] [4]] [4]
Screenshot [![enter image description here][4]][4]
因为文件\obj\Debug\netcoreapp3.0\Razor\Pages\Shared\_Layout.cshtml.g.cs
位于Razor类库Microsoft.AspNetCore.Identity.UI (3.0.0)
中,所以我无法对其进行编辑.
Because file \obj\Debug\netcoreapp3.0\Razor\Pages\Shared\_Layout.cshtml.g.cs
stand inside Razor Class Library Microsoft.AspNetCore.Identity.UI (3.0.0)
therefore I cannot edit it.
如何解决?
推荐答案
这是个问题,
生成的代码是
Microsoft.AspNetCore.Hosting
@using Microsoft.AspNetCore.Mvc.ViewEngines
@inject IWebHostEnvironment Environment
@inject ICompositeViewEngine Engine
它丢失了@using
应该是
@using Microsoft.AspNetCore.Hosting
我在 https://github.com/aspnet/Scaffolding/issues/1094
这篇关于找不到类型或名称空间名称"IWebHostEnvironment"(您是否缺少using指令或程序集引用?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!