1、备份你的项目
2、从Web API升级到Web API 2,修改global.asax,将 ? 1 WebApiConfig.Register(GlobalConfiguration.Configuration); 修改为 ? 1 GlobalConfiguration.Configure(WebApiConfig.Register);
3、通过Nuget,更新下面的包
包名 旧版本 新版本
Microsoft.AspNet.Razor 2.0.x.x 3.0.0
Microsoft.AspNet.WebPages 2.0.x.x 3.0.0
Microsoft.AspNet.WebPages.WebData 2.0.x.x 3.0.0
Microsoft.AspNet.WebPages.OAuth 2.0.x.x 3.0.0
Microsoft.AspNet.Mvc 4.0.x.x 5.0.0
Microsoft.AspNet.Mvc.Facebook 4.0.x.x 5.0.0
Microsoft.AspNet.WebApi.Core 4.0.x.x 5.0.0
Microsoft.AspNet.WebApi.SelfHost 4.0.x.x 5.0.0
Microsoft.AspNet.WebApi.Client 4.0.x.x 5.0.0
Microsoft.AspNet.WebApi.OData 4.0.x.x 5.0.0
Microsoft.AspNet.WebApi 4.0.x.x 5.0.0
Microsoft.AspNet.WebApi.WebHost 4.0.x.x 5.0.0
Microsoft.AspNet.WebApi.Tracing 4.0.x.x 5.0.0
Microsoft.AspNet.WebApi.HelpPage 4.0.x.x 5.0.0
Microsoft.Net.Http 2.0.x. 2.2.x.
Microsoft.Data.OData 5.2.x 5.6.x
System.Spatial 5.2.x 5.6.x
Microsoft.Data.Edm 5.2.x 5.6.x
Microsoft.AspNet.Mvc.FixedDisplayModes Removed
Microsoft.AspNet.WebPages.Administration Removed
Microsoft-Web-Helpers Removed
Microsoft.AspNet.WebHelpers Removed
4、更新根目录的web.config
12 3 4 5 6 7 8 9 10 < add key = "webpages:Version" value = "3.0.0.0" /> 11 < add key = "webpages:Enabled" value = "false" /> 12 < add key = "PreserveLoginUrl" value = "true" /> 13 < add key = "ClientValidationEnabled" value = "true" /> 14 < add key = "UnobtrusiveJavaScriptEnabled" value = "true" /> 15 < securityPolicy >
5、修改View文件夹下的web.config
1 < host factoryType = "System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 2 < add namespace = "System.Web.Mvc" /> 3 < pages validateRequest = "false" pageParserFilterType = "System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType = "System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType = "System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" > 4 < controls >5 < add assembly = "System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace = "System.Web.Mvc" tagPrefix = "mvc" />6 < configSections > 7 < sectionGroup name = "system.web.webPages.razor" type = "System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" >8 < section name = "host" type = "System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission = "false" /> 9 < section name = "pages" type = "System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission = "false" />
6、右键解决方案,选择卸载项目
7、右键项目,编辑 [ProjectName].csproj
8、找到 ProjectTypeGuids 节,删除Guid {E3E379DF-F4C6-4180-9B81-6769533ABE47},保存
9、右键项目,重新加载项目