【问题标题】:Strange MsBuild Error (Everything builds fine in Visual Studio)奇怪的 MsBuild 错误(在 Visual Studio 中一切正常)
【发布时间】:2013-08-06 02:23:32
【问题描述】:

首先,我为我的 stackoverflow 问题尝试了较短版本的代码,但这不会导致我的编译器错误。另外,我不能使用 AspnetCompiler 而不是 MsBuild,因为我正在构建一个包含多个网站和类库的解决方案。我的构建服务器设置已经存在多年,我从来没有遇到过这样的问题。我有一个在 C# 中广泛使用的 VB.Net 库,在该库中我有以下内容:

   Public Class PropertyParticipants

        Public Property Participants As List(Of Participant)
        Private _propertyId As Integer

        Public Sub New(propertyId As Integer)
            Participants = New List(Of Participant)()
            _propertyId = propertyId

            LoadParticipants()
        End Sub
  End Class

  Public Class Participant

    Public Property Role As ParticipantRole
    Public Property Type As ParticipantType
    Public Property FirstName As String
    Public Property LastName As String
    Public Property Password As String
    Public Property LoginId As String
    Public Property Initials As String
    Public Property UserId As Integer


    Public ReadOnly Property FullName() As String
        Get
            Return Me.FirstName & " " & Me.LastName
        End Get
    End Property

    Public Enum ParticipantRole
        Primary
        Party
        Pending
    End Enum

    Public Enum ParticipantType
        Seller
        Buyer
    End Enum

End Class

然后在我的 c# 代码后面我有以下内容

        PropertyParticipants propPart = new PropertyParticipants(PropertyId);

        foreach (Participant part in propPart.Participants.Where(p => p.Role != Participant.ParticipantRole.Pending))
        {
           int userId = part.UserId; //this is fine
            string loginId = part.LoginId; //compiler error
     }

错误 CS1061:“Participant”不包含“LoginId”的定义,并且找不到接受“Participant”类型的第一个参数的扩展方法“LoginId”(您是否缺少 using 指令或程序集引用?)

【问题讨论】:

  • 我错过了实际的编译错误吗?
  • 抱歉,编译器错误已添加到我的问题中

标签: c# asp.net vb.net msbuild


【解决方案1】:

尝试在 Visual Studio 中手动重建解决方案的每个项目并检查是否出现错误。由于同一解决方案(任何 CPU 和 x86)中具有不同平台的两个项目,我遇到了类似的问题。

【讨论】:

  • 谢谢,但这不在 Visual Studio 中,它在 Cruise Control.net 的构建服务器上,在 Visual Studio 中一切正常。
  • 关于我的问题并不重要,我有 3 个网站和 8 个或 9 个类库,它们通常每天构建 20 次。
【解决方案2】:

答案是哒哒哒:虽然 MSBuild 错误并没有告诉您并且 Visual Studio 编译得很好,但强制转换确保 MSBuild 编译器正确理解。很明显,从我的 VB.NET dll 转换为在 C# 中使用它的过程中丢失了一些信息。特别是泛型和 lambda 匿名函数并没有像人们期望的那样优雅地隐式转换。

foreach (Participant part in propPart.Participants.Cast<Kazork.AppCode.Users.Participant>  ().Where()){
            int userId = part.UserId; //this is fine
            string loginId = part.LoginId; //this now compliles
}

【讨论】:

  • “MSBuild 编译器”实际上是 csc,这与 Visual Studio 使用的完全相同,除非您使用不同的 PATH/Framework/... 环境变量。
  • 我相信 Visual Studio 实际上可能会在我的网站上使用 AspNetCompiler,我认为这就是为什么一切都可以在本地构建良好但在推送到构建服务器时出现问题。
猜你喜欢
  • 1970-01-01
  • 2014-07-15
  • 1970-01-01
  • 2011-05-07
  • 2015-02-18
  • 1970-01-01
  • 1970-01-01
  • 2018-03-19
  • 2011-12-31
相关资源
最近更新 更多