且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否所有的ASP.NET MVC 4 RC组件确实需要一个ASP.NET的WebAPI RC部署?

更新时间:2023-11-21 16:00:40

没有,你并不需要所有这些组件。

我总是preFER从的从头的构建我的Web API项目。我不使用的模板。我只是创建一个空的ASP.NET项目并添加 Microsoft.AspNet.WebApi 的NuGet包。

下面是似乎只需要引用:

  Microsoft.CSharp
Microsoft.Web.Infrastructure // Microsoft.Web.Infrastructure的NuGet包
Newtonsoft.Json // Newtonsoft.Json的NuGet包
System.Net.Http // Microsoft.Net.Http的NuGet包
System.Net.Http.Formatting // Microsoft.AspNet.WebApi.Client的NuGet包
System.Net.Http.WebRequest // Microsoft.Net.Http的NuGet包
System.Web.DynamicData
System.Web.Entity
System.Web.ApplicationServices
System.ComponentModel.DataAnnotations
系统
System.Data这
System.Core程序
System.Data.DataSetExtensions
System.Web.Extensions程序
System.Web.Http // Microsoft.AspNet.WebApi.Core的NuGet包
System.Web.Http.WebHost // Microsoft.AspNet.WebApi.WebHost的NuGet包
System.Xml.Linq的
System.Drawing中
的System.Web
的System.Xml
系统配置
System.Web.Services
的System.EnterpriseServices

When I created a "Empty WebAPI" project in Visual Studio 2010, several of the new assemblies to support the MVC web pages were added as references (an example of the few in the list below):

  • System.Web.Razor.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll

For the sake of cleanliness, I removed those DLL references that I wasn't using (or so I thought I wasn't "using"). When deploying to the server I would get exceptions like the following:

Exception message: Could not load file or assembly 'System.Web.Razor,Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

I am currently doing a bin deploy to the server with all of the assemblies it took until the JIT compliation errors ceased.

I understand the FileNotFoundException. I understand that the runtime is trying to resolve that reference.

My question(s): Why is it necessary to carry around the MVC Razor assemblies when all you are trying to create is a WebAPI site? Is there another dependency that needs to be removed?

No, you don't need all those assemblies.

I always prefer to build my Web API projects from scratch. I don't use the templates. I simply create an empty ASP.NET Project and add the Microsoft.AspNet.WebApi NuGet package.

Here are the references that seem to only be needed:

Microsoft.CSharp
Microsoft.Web.Infrastructure   // Microsoft.Web.Infrastructure NuGet package
Newtonsoft.Json                // Newtonsoft.Json NuGet package
System.Net.Http                // Microsoft.Net.Http NuGet package
System.Net.Http.Formatting     // Microsoft.AspNet.WebApi.Client NuGet package
System.Net.Http.WebRequest     // Microsoft.Net.Http NuGet package
System.Web.DynamicData
System.Web.Entity
System.Web.ApplicationServices
System.ComponentModel.DataAnnotations
System
System.Data
System.Core
System.Data.DataSetExtensions
System.Web.Extensions
System.Web.Http                // Microsoft.AspNet.WebApi.Core NuGet package
System.Web.Http.WebHost        // Microsoft.AspNet.WebApi.WebHost NuGet package
System.Xml.Linq
System.Drawing
System.Web
System.Xml
System.Configuration
System.Web.Services
System.EnterpriseServices