文章編號: 248078 - 上次校閱: 2002年10月15日 - 版次: 1.1

注意: VSSVersion 集合並不會提供檔案名稱

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。

在此頁中

全部展開 | 全部摺疊

徵狀

當執行迴圈 VSSVersions 集合,動作是關於檔案的名稱不是隨時可用的。

解決方案

[新增] 動作的一個解決方法是版本的比較有問題與前一版中專案項目。 任何檔案是在目前的版本,而不是在前一版是已加入的檔案。

狀況說明

Microsoft 已確認這是在本文開頭所列之 Microsoft 產品中的有錯誤。

其他相關資訊

重製行為的步驟

注意:此程序使用 Microsoft Visual Basic,但相同可能會在其他語言中完成。
  1. 在 Visual Basic 中建立標準的 EXE 專案。
  2. 建立 Microsoft SourceSafe 6.0 (或 5.0) 參考程式庫 (Ssapi.dll)。
  3. 新增指令按鈕至 Form1。
  4. 按兩下按鈕。
  5. 下列程式碼貼 Command1_Click Sub 中:
    Dim SSDB As New VSSDatabase
    Dim SSItem As VSSItem
    Dim TempItem As VSSItem
    Dim oVersion As VSSVersion
    Dim verDate As Date
    Dim User As String
    Dim Comment As String
    Dim Action As String
    
    ' Open SourceSafe database
    ' NOTE: If your path to srcsafe.ini, username, and password information
    '       differ from what is listed below, please adjust it accordingly.
             
    
    SSDB.Open "C:\Program Files\Microsoft Visual Studio\Common\VSS\srcsafe.ini", "Admin", ""
        
    ' Get project to search
    Set SSItem = SSDB.VSSItem("$/Project_To_Retrieve_History")
    
    ' Loop through the Versions collection getting each event
    For Each oVersion In SSItem.Versions(VSSFlags.VSSFLAG_RECURSYES)
        ' Get the action for the current version
        Action = oVersion.Action
            
        ' Check what the action is and print out what we find.
        If InStr(1, Action, "Added", vbTextCompare) > 0 Then
            ' Get the VSSItem the version contains
            Set TempItem = oVersion.VSSItem
                
            ' Get the date, username, and comment from the version item.
            verDate = oVersion.Date
            User = oVersion.UserName
            Comment = oVersion.Comment
                
            ' Print out the item we have
            Debug.Print "Added: " & TempItem.Name & " by " & User & " at " & Format(verDate, "General Date") & Comment
        End If
    Next
    					
  6. 執行程式。
  7. 若要實作因應措施上述,貼上下列 (請注意這是不只是 Command1_Click Sub):
    Dim SSDB As New VSSDatabase
    Dim SSItem As VSSItem
    Dim TempItem As VSSItem
    Dim oVersion As VSSVersion
    Dim verDate As Date
    Dim User As String
    Dim Comment As String
    Dim Action As String
    Dim tItem As VSSItem
    Dim oItem As VSSItem
    Dim bad As Boolean
    Dim sTempItem As VSSItem
    
    Private Sub Command1_Click()
        ' Open SourceSafe database
        ' NOTE: If your path to srcsafe.ini, username, and password information
        '       differ from what is listed below, please adjust it accordingly.
        SSDB.Open "C:\Program Files\Microsoft Visual Studio\Common\VSS\srcsafe.ini", "Admin", ""
        
        ' Get project to search
        Set SSItem = SSDB.VSSItem("$/Project_To_Retrieve_History")
        
        ' Loop through the Versions collection getting each event
        For Each oVersion In SSItem.Versions(VSSFlags.VSSFLAG_RECURSYES)
            ' Get the action for the current version
            Action = oVersion.Action
            
            ' Check what the action is and print out what we find.
            If InStr(1, Action, "Added", vbTextCompare) > 0 Then
                ' Get the VSSItem the current version contains
                Set TempItem = oVersion.VSSItem
                
                ' Get the date, username, and comment from the version item.
                verDate = oVersion.Date
                User = oVersion.UserName
                Comment = oVersion.Comment
                
                ' See if we can use the Items collection
                If CheckItem = 1 Then
                    ' If we have a project and the items collection has items, print out each item in the collection.
                    ' We could have an items collection but have 0 items in it, so check for that case.
                    If TempItem.Type = VSSItemType.VSSITEM_PROJECT And TempItem.Items.Count > 0 Then
                        ' Get the previous version
                        Set sTempItem = TempItem.Version(TempItem.VersionNumber - 1)
                                            
                        ' Loop through the items at this version
                        For Each tItem In TempItem.Items
                            bad = False
    
                            ' Loop through the previous version
                            For Each oItem In sTempItem.Items
                                ' Check if the names are the same
                                If oItem.Spec = tItem.Spec Then
                                    ' Found the name, not the one we are looking for
                                    bad = True
                                    Exit For
                                End If
                            Next
                            
                            ' If this is the file added, print out the information
                            If bad = False Then
                                Debug.Print "Added: " & tItem.Name & " in " & TempItem.Name & " by " & User & " at " & Format(verDate, "General Date") & Comment<BR/>
                            Exit For   
                            End If
                        Next
                    Else
                        ' Otherwise just print out the item we have
                        Debug.Print "Added: " & TempItem.Name & " by " & User & " at " & Format(verDate, "General Date") & Comment
                    End If
                Else
                    ' No items collection, just print out the item we have
                    Debug.Print "Added: " & TempItem.Name & " by " & User & " at " & Format(verDate, "General Date") & Comment
                End If
            End If
        Next
    End Sub
    
    '*****************************************************
    ' Purpose:  Check to see if we can look at the Items
    '           collection.  This keeps us from getting an
    '           error from SourceSafe.
    '
    ' Inputs:   None
    '
    ' Returns:  1 if the Items collection exists and can be used.
    '           0 if the Items collection does not exist.
    '
    '*****************************************************
    Private Function CheckItem()
        ' If we have a problem, go to the error handler
        On Error GoTo ErrHandler
        
        ' Try to access the Items collection and see if we succeed or not
        Dim i As Integer
        i = TempItem.Items.Count
        
        ' It worked, so return 1
        CheckItem = 1
        Exit Function
        
    ErrHandler:
        ' Return 0 - meaning there is a problem
        CheckItem = 0
    End Function
    					
  8. 執行程式。

?考

如需詳細資訊請造訪下列 Microsoft 網站]:
Visual SourceSafe 6.0 自動化
http://msdn.microsoft.com/en-us/library/bb509341.aspx (http://msdn.microsoft.com/en-us/library/bb509341.aspx)

這篇文章中的資訊適用於:
  • Microsoft Visual SourceSafe 5.0 Standard Edition
  • Microsoft Visual SourceSafe 6.0 Standard Edition
關鍵字:?
kbmt kbautomation kbbug kbnofix KB248078 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:248078? (http://support.microsoft.com/kb/248078/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。