ChatGPT解决这个技术问题 Extra ChatGPT

How do we determine whether we are using Web API 1 or Web API 2?

Introduce the problem

I would like to know whether we are using Web API 1 or 2. My own packages.config indicates version 5.0.0. Is that Web API 1 or 2?

Search, and research

I have tried Googling the following:

"web api 1" "web api 2"

and

ASP.NET Web API release history

and

ASP.NET Web API nuget

The best references seem to be these two nuget pages:

ASP.NET Web API Nuget seems to indicate that anything 4.* is Web API 1,

Microsoft ASP.NET Web API 2.1 Nuget that anything 5.* is Web API 2.

Is that right? How would I know for sure?

Install-Package Microsoft.AspNet.WebApi -Version 5.2.7 reference nuget.org/packages/Microsoft.AspNet.WebApi

J
John

I think what you found seems correct. I had the same question then I had a look under my installed packages when you go "Manage Nuget packages". There was an item installed with the name "Microsoft ASP.NET WEB API 2.2". So I was able to determine my own version from there.


in VS2015, you can check packages.config file for version.
The title of the package on NuGet shows the version number: nuget.org/packages/Microsoft.AspNet.WebApi
S
SerjG

I'm not sure what @John meant with the package name above. I'm having the following package right now:

Microsoft.AspNet.WebApi.5.2.3

Based on this article http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-22 I assume that starting from the package version 5.2.2 it's Web API 2.2 version.


I hate that, you check the packages file and it says it's version 5 but actually is version 2, I hate this versions hell
Same here, v5.2.3. Thanks!
The article: "The latest ASP.NET Web API 2.2 package has the following version: '5.2.0'"
R
RBT

I always try this instead -

In the controller make a method

public IHttpActionResult MyResult(){
    return Ok();
}

If you get compilation error then it is API 1.0.

If no compilation error then you are referencing API 2.0.