简体   繁体   中英

ASP.NET 5 - Starting an ASP.NET vNext project

I am trying to get my feet wet with ASP.NET vNext. I'm very interested in the cross-platform aspect of it. For that reason, I'm focused on using the K Runtime Environment.

I've looked at the sample provided on the home page . Those samples do not help me though. I have a project that is structure like this:

/
 /client
 /server
  /controllers
   HomeController.cs
  /views
   /home
     Index.cshtml
  project.json
  Startup.cs

When I navigate to the directory with project.json, I run the following from the command-line.

C:\MyProject\server>k web

I get the following error:

System.IO.FileLoadException: Could not load file or assembly 'server' or one of its dependencies. General Exception (Exception from HRESULT: 0x80131500)
File name: 'server' ---> Microsoft.Framework.Runtime.Roslyn.RoslynCompilationException: C:\MyProject\server\controllers\HomeController.cs(5,18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

I feel like Startup.cs is looking for something called server . Yet it doesn't exist. I suspect something is missing from project.json . However, I do not know what. My project.json looks like the following:

{
    "dependencies": {
        "Kestrel": "1.0.0-beta1",
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta1",
        "Microsoft.AspNet.Hosting": "1.0.0-beta1",
        "Microsoft.AspNet.Mvc": "6.0.0-beta1",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta1"
    },
    "commands": {
        "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001"
    },
     "frameworks": {
        "aspnet50": {},
        "aspnetcore50": {}
  }
}

What am I doing wrong? Thank you!

As Tim has pointed out there's something fishy in your controllers.

The compiler asks for System.Web but you shouldn't use it. Is it referenced somewhere? vNext is moving away from System.Web; we should not use it in MVC 6 .

Are you using the stock New Project? Are you using the latest CTP/Preview version?

If you are using the stock New Project just try recreate the project. Yes, I have solved an error in VS 2015 by only recreating the stock project.

I would recommend you to read this article:
http://www.dzone.com/articles/developing-and-self-hosting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM