ASP.NET 5 on Visual Studio 2015 addMvc method not found

我是研究僧i 提交于 2019-12-10 17:26:52

问题


I am following this tutorial: http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6 to setup a web api and I have not made it very far. Once I added the line: services.addMvc(); I got an exception saying this method is not found. I searched online and found a separate question/answer here: http://forums.asp.net/t/2026087.aspx but that did not help.

My startup.cs looks like this:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseMvc();

        app.UseWelcomePage();
    }

And my project.json:

{
"webroot": "wwwroot",
"version": "1.0.0-*",
"exclude": [
    "wwwroot"
],
"packExclude": [
    "node_modules",
    "bower_components",
    "**.kproj",
    "**.user",
    "**.vspscc"
],
"dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta1",
    "Microsoft.AspNet.Mvc": "6.0.0-beta1"
},
"frameworks" : {
    "aspnet50" : { },
    "aspnetcore50" : { }
}
}

回答1:


Mostly sure you are using some incorrect packages. Try to create the default starter application that comes with VS (use the latest VS 2015) and see exactly what packages to use.

A few comments based on the contents of yourproject.json file:

  1. For now, do not mix different versions of beta packages (like beta1 and beta2). That's a recipe for disaster :)
  2. Beta1 is old, please upgrade



回答2:


After I had added "Microsoft.AspNet.Mvc": "6.0.0-beta2" to project.json and saved the file my dependencies didn't automatically get restored. I had to close and reopen the solution. After I did that the packages were restored and the error went away. I'm sure there is a more simple way to restore, but that's what worked for me.



来源:https://stackoverflow.com/questions/28127307/asp-net-5-on-visual-studio-2015-addmvc-method-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!