问题
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:
- For now, do not mix different versions of beta packages (like beta1 and beta2). That's a recipe for disaster :)
- 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