C# 奇怪的MsBuild错误(在VisualStudio中一切都可以正常生成)

C# 奇怪的MsBuild错误(在VisualStudio中一切都可以正常生成),c#,asp.net,vb.net,msbuild,C#,Asp.net,Vb.net,Msbuild,首先,我尝试了一个较短版本的代码来解决stackoverflow问题,但这并没有导致编译器错误。此外,我无法使用AspnetCompiler而不是MsBuild,因为我正在构建一个包含多个网站和类库的解决方案。我的构建服务器设置已经存在多年了,我从来没有遇到过这样的问题。我有一个VB.Net库,我在C#中广泛使用该库,在该库中我有以下内容: Public Class PropertyParticipants Public Property Participants As

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

   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:“参与者”不包含“LoginId”的定义,并且找不到接受“参与者”类型的第一个参数的扩展方法“LoginId”(是否缺少using指令或程序集引用?

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

答案是:尽管MSBuild错误不会告诉您,Visual Studio编译得很好,但casting确保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
}
foreach(propPart.Participants.Cast().Where()中的参与者部分){
int userId=part.userId;//这很好
string loginId=part.loginId;//这个现在是compliles
}

我错过了实际的编译错误是什么吗?对不起,我的问题中添加了编译器错误。谢谢,但这不在Visual Studio中,它在Cruise Control.net的生成服务器上,在Visual Studio中一切都可以正常生成。这与我的问题无关,我有3个网站和8或9个类库,它们通常每天一起构建20次。“MSBuild编译器”实际上是csc,这与Visual Studio使用的完全相同,除非您使用不同的路径/框架/。。。环境变量。我相信VisualStudio可能会在我的网站上使用AspNetCompiler,我认为这就是为什么所有东西都可以在本地构建,但在推送到构建服务器时,我遇到了一个问题。