【问题标题】:Build Errors - 'System.Web.Mvc.ModelClientValidationRule' Conflicts构建错误 - 'System.Web.Mvc.ModelClientValidationRule' 冲突
【发布时间】:2012-01-20 16:08:35
【问题描述】:

我正在尝试在 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\v2.0\Assemblies\System.Web.WebPages.dll' C:\Users\brownp\Documents\Visual Studio 2010\Projects \Cab\Cab\Models\AccountModels.cs 223 28 驾驶室

此外,每次我打开解决方案时,它都会提示我以下内容:

我通过 Web 平台安装程序安装,它安装成功,但是每次打开解决方案时都会重新出现该消息。

任何人都可以提供任何指导吗?

谢谢保罗

【问题讨论】:

    标签: asp.net-mvc visual-studio asp.net-webpages


    【解决方案1】:

    今天安装 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 "/>
    

    【讨论】:

    • 我终于能够验证只需添加 Version=1.0.0.0 就足够了。因此
    • 对于 MVC5 使用 version=2.0.0.0
    • 在引用列表中选择System.Web.WebPages,并将Specific Version 属性更改为False 对我有用。
    • @EvgenyGorb -- 适用于 MVC 3、4 或 5? ...只是为了每个人的利益。谢谢
    • @TomStickel - 我将它用于 MVC 4,但我想它也适合其他版本
    【解决方案2】:

    好的,试试这个解决方案...

    1. 在根 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

    【讨论】:

      【解决方案3】:

      从解决方案引用中删除 System.Web.WebPages。就是这样。

      【讨论】:

        【解决方案4】:

        避免这种冲突的最好方法是-

        1. 转到解决方案资源管理器
        2. 参考
        3. 右击System.Web.WebPages
        4. 移除

        现在运行您的应用程序并享受吧!

        【讨论】:

          【解决方案5】:

          这个问题与您在 VS2010 中描述的相同,在我的 VS2015 中使用较新版本的 MVC (V5) 时发生。

          以下是我修复它的方法:

          • 将 NUGET 包更新到最新版本。

          • 在您的项目中,删除对 Microsoft.AspNet.WebPages 的引用。然后,使用最新的包重新添加引用(使用“浏览...”):

            C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40

          • 确保所有项目都引用相同的程序集,如果没有,请按上述方法修复它们。然后,重新构建解决方案。就我而言,它修复了错误。

          检查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>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2019-03-23
            • 2018-06-22
            • 1970-01-01
            • 2021-12-29
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多