我正在尝试在 VS2010 中“构建”我的 MVC3 Web 应用程序,但是不断收到以下错误:
错误 2 类型“System.Web.Mvc.ModelClientValidationRule”同时存在于“c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll”和“ c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages 2.0\Assemblies\System.Web.WebPages.dll' C:\Users rownp\Documents\Visual Studio 2010\Projects\Cab\Cab\模型\AccountModels.cs 223 28 驾驶室
此外,每次我打开解决方案时,它都会提示我以下内容:
我通过 Web 平台安装程序安装并且安装成功,但是每次打开解决方案时该消息都会重新出现。
有人可以提供任何指导吗?
谢谢保罗
今天安装 MVC4 beta 后,我的一些 MVC 3 项目无法编译。 (ModelClientValidationRule 冲突)修复是:
编辑:
ProjectName.csproj
改变
<Reference Include="System.Web.WebPages"/>
至
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
好的,尝试这个解决方案...
在根 Web.config 文件中,添加一个新条目,其中包含键 webPages:Version 和值 1.0.0.0。
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
2.In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
3.Locate the following assembly references:
<Reference Include="System.Web.WebPages"/>
<Reference Include="System.Web.Helpers" />
将其替换为以下内容:
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
4.保存更改,关闭正在编辑的项目(.csproj)文件,然后右键单击该项目并选择重新加载。
参考:http://forums.asp.net/t/1723108.aspx/1
也可以尝试:http://www.asp.net/learn/whitepapers/mvc4-release-notes#_Toc303253815
从解决方案引用中删除
System.Web.WebPages
。就这些了。
避免这种冲突的最好方法是-
System.Web.WebPages
现在运行您的应用程序并享受吧!
这个问题与您在 VS2010 中描述的相同,在我使用较新版本的 MVC (V5) 的 VS2015 中出现。
这是我修复它的方法:
将 NUGET 包更新到最新版本。
在您的项目中,删除对 Microsoft.AspNet.WebPages 的引用。然后,使用最新的包重新添加引用(使用“浏览...”):
C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP.NET网页2.0 \ Packages \ Microsoft.AspNet.WebPages.2.0.30506.0 \ lib 等40
确保所有项目都引用相同的程序集,如果不是,请按照上述方式修复它们。然后,重新构建解决方案。就我而言,它修复了错误。
检查
Web.config
文件,并修复设置,例如:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="true" />
...
<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>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>