【问题标题】:CompareAttribute isn't found when building in TeamCity (on Windows Server 2012 RC)在 TeamCity 中构建时找不到 CompareAttribute(在 Windows Server 2012 RC 上)
【发布时间】:2012-07-12 19:09:14
【问题描述】:

我正在尝试在安装了 Windows Server 2012 RC 的服务器上的 TeamCity 上构建 MVC 项目。

我收到以下错误。它看起来像是与 MVC 版本的某种冲突,如果我在谷歌搜索时发现了这种冲突。我正在按版本明确引用 system.web.mvc 等,所以我不知道问题是什么。有什么想法吗?

Models\AccountModels.cs(26, 10): error CS0246: The type or namespace name 'Compare' could not be found (are you missing a using directive or an assembly reference?) 
Models\AccountModels.cs(26, 10): error CS0104: 'CompareAttribute' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute' 
Models\AccountModels.cs(64, 10): error CS0246: The type or namespace name 'Compare' could not be found (are you missing a using directive or an assembly reference?) 
Models\AccountModels.cs(64, 10): error CS0104: 'CompareAttribute' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute' 

【问题讨论】:

    标签: asp.net-mvc-3 teamcity windows-server


    【解决方案1】:

    您必须在Compare 属性中明确指定命名空间,例如

    [System.Web.Mvc.Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
    

    而不是

    [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
    

    【讨论】:

    • 在升级到 VS2012 和相关的项目目标更改后也开始看到这个问题。
    【解决方案2】:

    您还可以添加:

    using System.Web.Mvc;
    

    在 .cs 文件的顶部

    【讨论】:

      【解决方案3】:

      我将我的站点从 MVC Framework 4 更新到 4.5.1,并且(在使用 NuGet 命令行更新各种库之后)我收到了同样的错误。我已经调用了命名空间'using System.Web.Mvc;'在我的 .cs 文件的顶部。仅当我使用完整路径“System.Web.Mvc.Compare”时才有效。

      【讨论】:

        【解决方案4】:

        使用 System.Web.Mvc 从标头中删除

        【讨论】:

          猜你喜欢
          • 2013-11-16
          • 1970-01-01
          • 2015-10-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多