在Visual Studio的2015年addMvc方法ASP.NET 5未找到 [英] ASP.NET 5 on Visual Studio 2015 addMvc method not found

查看:227
本文介绍了在Visual Studio的2015年addMvc方法ASP.NET 5未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面这个教程:的 http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6 设置Web API,我已经不是很远使它。有一次,我添加了一行: services.addMvc(); 我得到一个异常说这种方法是找不到的。我在网上搜索,并在这里找到一个单独的问题/回答: http://forums.asp.net/t /2026087.aspx 但这并没有帮助。

我startup.cs看起来是这样的:

 公共无效ConfigureServices(IServiceCollection服务)
    {
        services.AddMvc();
    }    公共无效配置(IApplicationBuilder应用程序)
    {
        app.UseMvc();        app.UseWelcomePage();
    }

和我project.json:

  {
根目录:wwwroot的
版本:1.0.0- *,
排除」:
    wwwroot的
]
packExclude:[
    node_modules
    bower_components
    **。kproj
    **。用户,
    **。vspscc
]
依赖:{
    Microsoft.AspNet.Server.IIS:1.0.0-β2
    Microsoft.AspNet.Diagnostics:1.0.0-β1
    Microsoft.AspNet.Mvc:6.0.0-β1
},
构架 : {
    aspnet50:{},
    aspnetcore50:{}
}
}


解决方案

晴确保您使用的一些不正确的包。尝试创建带有VS默认启动的应用程序(使用最新的2015年VS),看​​看到底哪些软件包使用。

根据您的 project.json 文件的内容,需要注意几点:


  1. 现在,不要混用测试包的不同版本(如β1的和β2)。这是一个灾难:)

  2. Beta1的是旧的,请升级

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" : { }
}
}

解决方案

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

这篇关于在Visual Studio的2015年addMvc方法ASP.NET 5未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆