在ASP.NET Core 1中呈现视图时找不到BCL类

时间:2016-03-06 20:48:45

标签: asp.net-mvc asp.net-core

我正在尝试启动并运行基本的ASP.NET MVC Core 1项目(来自aspnetcidev feed的软件包,DNX SDK 1.0.0-rc2-16551)。我为该项目运行Kestrel,但当我尝试导航到Home/Index时,我遇到了许多运行时错误:

Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
  An unhandled exception was thrown by the application.
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
3g0a2dps.mjy(4,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(5,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(6,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(7,11): error CS0246: The type or namespace name 'Microsoft' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(8,11): error CS0246: The type or namespace name 'Microsoft' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(9,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(11,50): error CS0246: The type or namespace name 'Microsoft' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(11,91): error CS1980: Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference?
3g0a2dps.mjy(11,91): error CS0518: Predefined type 'System.Boolean' is not defined or imported
3g0a2dps.mjy(19,16): error CS0518: Predefined type 'System.Object' is not defined or imported
3g0a2dps.mjy(19,16): error CS0246: The type or namespace name 'Microsoft' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(19,63): error CS0518: Predefined type 'System.Void' is not defined or imported
3g0a2dps.mjy(21,16): error CS0518: Predefined type 'System.Object' is not defined or imported
3g0a2dps.mjy(21,16): error CS0246: The type or namespace name 'Microsoft' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(21,79): error CS0518: Predefined type 'System.Void' is not defined or imported
3g0a2dps.mjy(23,16): error CS0518: Predefined type 'System.Object' is not defined or imported
3g0a2dps.mjy(23,16): error CS0246: The type or namespace name 'Microsoft' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(23,75): error CS0518: Predefined type 'System.Void' is not defined or imported
3g0a2dps.mjy(25,16): error CS0518: Predefined type 'System.Object' is not defined or imported
3g0a2dps.mjy(25,16): error CS0246: The type or namespace name 'Microsoft' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(25,63): error CS0518: Predefined type 'System.Object' is not defined or imported
3g0a2dps.mjy(25,63): error CS1980: Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference?
3g0a2dps.mjy(25,63): error CS0518: Predefined type 'System.Boolean' is not defined or imported
3g0a2dps.mjy(25,84): error CS0518: Predefined type 'System.Void' is not defined or imported
3g0a2dps.mjy(30,36): error CS1983: The return type of an async method must be void, Task or Task<T>
3g0a2dps.mjy(30,31): error CS0518: Predefined type 'System.Object' is not defined or imported
3g0a2dps.mjy(30,31): error CS0246: The type or namespace name 'Task' could not be found (are you missing a using directive or an assembly reference?)
3g0a2dps.mjy(30,36): error CS0115: 'ASPV__Views_Home_Index_cshtml.ExecuteAsync()': no suitable method found to override

等等。似乎Razor缺少BCL课程,但此时我不知道如何提供这些课程。

这是我的project.json

{
   "version": "1.0.0-*",
   "compilationOptions": {
      "emitEntryPoint": true,
      "warningsAsErrors": true,
      "preserveCompilationContext": true
   },

   "tools": {
      "dotnet-publish-iis": "1.0.0-*",
      "dotnet-razor-tooling": "1.0.0-*"
   },

   "content": [
      "Areas",
      "Views",
      "wwwroot",
      "hosting.json",
      "config.json"
   ],

   "dependencies": {
      "Microsoft.AspNetCore.Diagnostics": "1.0.0-*",
      "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-*",
      "Microsoft.AspNetCore.Hosting": "1.0.0-*",
      "Microsoft.AspNetCore.Mvc": "1.0.0-*",
      "Microsoft.AspNetCore.Mvc.Razor": "1.0.0-*",
      "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-*",
      "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
      "Microsoft.AspNetCore.Server.WebListener": "0.1.0-*",
      "Microsoft.AspNetCore.Session": "1.0.0-*",
      "Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
      "Microsoft.Extensions.Logging.Console": "1.0.0-*"
   },

   "commands": {
      "web": "MyApp"
   },

   "frameworks": {
      "dnx451": { }
   },

   "exclude": [
      "wwwroot",
      "node_modules"
   ],
   "publishExclude": [
      "**.user",
      "**.vspscc"
   ]
}

这是我的global.json

{
   "projects": [ "src" ],
   "sdk": {
      "version": "1.0.0-rc2-16551"
   }
}

当前的MusicStore示例应用程序对我不起作用(很多缺少的引用),所以这也没有多大帮助。

有没有人知道从哪里拿起?

1 个答案:

答案 0 :(得分:3)

要使用DNX的最新MVC RC2夜间版本,您必须引用名为Microsoft.AspNetCore.Mvc.Dnx的兼容包,并使用services.AddMvcDnx()方法调用ConfigureServices()

阅读https://github.com/aspnet/Announcements/issues/154了解详情。