WebApi2 in visual studio 2012

后端 未结 5 1745
南旧
南旧 2021-02-18 17:07

How can I create a project that uses WebApi2 in visual studio 2012?

Do I have to create with a blank project or do I have to create a MVC project?

I don\'t want

5条回答
  •  庸人自扰
    2021-02-18 17:50

    My initial research led me to take the manual configuration approach I detail below, so I actually never tried Olav's suggestion. If that works, that's probably the way to go. But if not, or if there are missing pieces to that approach, here are the steps I took. I'm using VS 2012 Update 3.

    • Start with a new MVC 4 / Web API project
    • From the package manager console, run:

      Install-Package Microsoft.AspNet.WebApi -pre

    I received a warning that it was skipping _ViewStart.cshtml but it gave me the option to overwrite. I chose Yes.

    • Again from the package manager console, run:

      Install-Package Microsoft.AspNet.Mvc -Pre

    • Change web.config, views\web.config, and areas\views\web.config according to these instructions. Ignore steps 1 - 5 under Upgrade Steps. Also, I didn't need to do anything concerning WebHelpers.

    • Add references to System.Web.Http 5.0 to web.config according to step 2 of this answer.
    • If you build at this point, you'll get a compiler error stating that XmlDocumentationProvider in the Areas\HelpPage folder doesn't fully implement the interface. Not sure what that's all about, but at this point it's not important to me so I just added empty implementations to the two missing methods (tip: right click on IDocumentationProvider and select implement interface - it will add the two missing methods).

    I did this a couple days ago and my memory is already getting fuzzy, but I think that covers it. At this point I'm able to use WebAPI2 including attribute-based routing!

提交回复
热议问题