MVC程序集版本不兼容问题
First Error:检测到 ASP.NET Web Pages 的冲突版本: 指定的版本为“2.0.0.0”,而 bin 中的版本为“1.0.0.0”。要继续操作,请删除应用程序 bin 目录中的文件,或者删除 web.config 中的版本指定。
English version:Conflicting versions of ASP.NET WebPages detected: specified version is"1.0.0.0",
but the version in bin is"2.0.0.0".Tocontinue, remove files from the application's bin directory
or remove the version specification in web.config.
解决方案:
1。Open 'Package Manager Console' in Visual Studio
2。uninstall-package microsoft.aspnet.mvc
3。install-package microsoft.aspnet.mvc
second Error:
System.Collections.Generic.Dictionary`2<System.String,BlockParser> System.Web.Razor.Parser.CSharpCodeParser.get_RazorKeywords()”。
这些所有的错误都是因为版本不兼容问题,如果你想在MVC3 的版本下运用 razor 2也是可以的
步骤:
First :you can have a reference of system.web.Helpers and system.web.webPages in your reference assembly
Second:in your ROOT web.config(the bottom one),do some changes,UPDATE OR ADD
<appSettings>
<add key="webpages:Version" value="2.0.0.0"/>
<add key="webpages:Enabled" value="true" /> <add key="PreserveLoginUrl" value="true" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
Inside Views web.config file, add/update these settings,
<configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Now you can easily use Razor V2 features in inside ASP.NET MVC 3 view.
@{ int? nullValue = null; } <a href="~/WebForm1.aspx" class="@nullValue">MyLink</a>
Note: Before doing this, make sure you have installed ASP.NET MVC 4. Otherwise the trick will fail.
I must say the configuration of the Microsoft's platform is a little bit annoying.
These are the problems that bothers me very much ,then I share it with all of you.
All the version is availablehere:https://nuget.org/packages/Microsoft.AspNet.Mvc/