2013-08-06 30 views
0

首先,我嘗試了一個較短版本的代碼爲我的stackoverflow問題,但不會導致我的編譯器錯誤。另外,我無法使用AspnetCompiler而不是MsBuild,因爲我正在構建多個網站和類庫的解決方案。我的構建服務器設置已經存在多年,我從來沒有像這樣的任何問題。我有我的C#廣泛使用VB.Net圖書館,在圖書館中,我有以下幾點:奇怪的MsBuild錯誤(在Visual Studio中一切正常)

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'(您是否缺少使用指令或程序集引用?)

+0

我錯過了實際的編譯錯誤是什麼? –

+0

哎呀抱歉,編譯器錯誤添加到我的問題 –

回答

0

嘗試重建在Visual Studio和Chec中手動解決您的解決方案的項目如果出現錯誤我有一個類似的問題,因爲在同一解決方案中有兩個具有不同平臺的項目(任何CPU和x86)。

+0

謝謝,但這不是在Visual Studio中,它是在Cruise Control.net中的構建服務器上,在Visual Studio中一切正常。 –

+0

您在VS的解決方案中有多少個項目? –

+0

對於我的問題來說並不重要,我有3個網站和8或9個類庫,它們一般每天正常建造20次。 –

0

答案是da da dah:儘管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 
} 
+0

「MSBuild編譯器」實際上是csc,並且與Visual Studio使用的完全相同,除非您使用不同的PATH/Framework/...環境變量。 – stijn

+0

我相信Visual Studio實際上可能會爲我的網站使用AspNetCompiler,我認爲這就是爲什麼在本地生成一切正常的原因,但是推送到我的生成服務器時遇到問題。 –