手工升级ASP.NET MVC 3项目:
一.安装ASP.NET MVC 4
二.升级ASP.NET MVC版本配置信息:
1:替换项目 Web.config 中的
System.Web.Mvc, Version=3.0.0.0
System.Web.WebPages, Version=1.0.0.0
System.Web.Helpers, Version=1.0.0.0
System.Web.WebPages.Razor, Version=1.0.0.0
为最新4.0配置:
System.Web.Mvc, Version=4.0.0.0
System.Web.WebPages, Version=2.0.0.0
System.Web.Helpers, Version=2.0.0.0,
System.Web.WebPages.Razor, Version=2.0.0.0,
2:在Web.config中升级ASP.NET配置为版本: "2.0.0.0" ,并添加个新的节点:PreserveLoginUrl ,值为 "true":
<appSettings>
<add key="webpages:Version" value="2.0.0.0"/>
<add key="PreserveLoginUrl" value="true"/>
<appSettings>
3:在解决方案浏览器Solution Explorer中,引用最新的Solution Explorer, 删除System.Web.Mvc System.Web.Mvc (v4.0.0.0).
删除引用:
- System.Web.Mvc (v3.0.0.0)
- System.Web.WebPages (v1.0.0.0)
- System.Web.Razor (v1.0.0.0)
- System.Web.WebPages.Deployment (v1.0.0.0)
- System.Web.WebPages.Razor (v1.0.0.0)
添加引用:
- System.Web.Mvc (v4.0.0.0)
- System.Web.WebPages (v2.0.0.0)
- System.Web.Razor (v2.0.0.0)
- System.Web.WebPages.Deployment (v2.0.0.0)
- System.Web.WebPages.Razor (v2.0.0.0)
4:
在解决方案浏览器Solution Explorer,卸载当前项目,编辑ProjectName.csproj.
找到ProjectTypeGuids 元素,并替换{E53F8FEA-EAE0-44A6-8774-FFD645390401} 为 {E3E379DF-F4C6-4180-9B81-6769533ABE47}.
保存修改,关闭(.csproj) 文件,然后重新加载项目.
5:如果项目中有第三方组件引用了老版本的ASP.NET MVC, 可以在Web.config中加入三个 bindingRedirect元素
<configuration>
<!--... elements deleted for clarity ...-->
<runtime>
<assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirectold Version="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirectold Version="1.0.0.0-3.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirectold Version="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
这样升级就结束了。