【发布时间】:2019-10-08 14:38:28
【问题描述】:
我有一个现有的 ASP.NET 核心 2.2(SDK 版本 2.2.108)Web API,我现在正在添加 MVC 来托管一个带有控制器的网页。我已经添加:
- 新控制器
- 新的 .cshtml 视图
- 确保我的 startup.cs 包含 services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
我正在使用 Http.Sys,我得到 500 [Microsoft.AspNetCore.Server.HttpSys.MessagePump] ProcessRequestAsync。 如果我在 VS 2017 (15.9.13) 中启用异常,我会看到:
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: 'One or more compilation failures occurred:
310z1p4f.mzl(4,41): error CS0234: The type or namespace name 'Razor' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)
310z1p4f.mzl(5,40): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)
310z1p4f.mzl(4,82): error CS0518: Predefined type 'System.Type' is not defined or imported
310z1p4f.mzl(4,122): error CS0518: Predefined type 'System.String' is not defined or imported
它继续。
我在构建输出中看到:
Microsoft.AspNetCore.Razor.dll
Microsoft.AspNetCore.Razor.Language.dll
Microsoft.AspNetCore.Razor.Runtime.dll
我在 SO 和 github 上关注了几个不同的讨论:
- https://stackoverflow.com/a/51908353/5048049
- https://github.com/dotnet/standard/issues/542
- The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
- The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor'
- https://github.com/aspnet/AspNetCore.Docs/issues/8880
但没有运气。想法?
【问题讨论】:
-
我做了一个demo来测试,没有报错。你尝试更新最新版本的ASP.NET core 2.2 SDK吗?
-
我正在使用那个 SDK,因为我想使用 VS2017。但是我刚刚找到了罪魁祸首,我写了一个答案,以防其他人遇到同样的问题
标签: c# asp.net-mvc asp.net-core razor