将它放在您的 web.config 文件中。它将导致框架将依赖项重定向到适当的版本。
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<configuration>
从未来编辑
由于上述语法中指出的 XML 错误,我重新访问这篇文章时,还有一些其他地方很可能也需要更新。首先,在主 web.config 中,此行应在<appSettings>
部分中更改为以下内容
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
此外,views 文件夹中有一个 web.config,应更新为以下内容
<configSections>
<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">
<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" />
<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" />
</sectionGroup>
</configSections>
基本上,您想要识别所有提到 razor 2.0.0.0 的地方,并将它们更改为 3.0.0.0 以及程序集重定向。我相信我拥有上面确定的所有这些位置。
如果您更新整个 MVC 框架,还需要执行额外的工作,但这不是问题的基础。