Artigo: 248078 - Última revisão: terça-feira, 15 de Outubro de 2002 - Revisão: 1.1

Erro: Colecção de VSSVersion não apresentar os nomes de ficheiro

Dica do SistemaEste artigo aplica-se a um sistema operativo diferente do que está a utilizar. Foi desactivado o conteúdo do artigo, que pode não ser relevante para si.

Nesta página

Expandir tudo | Reduzir tudo

Sintomas

Quando o ciclo através do conjunto de VSSVersions, o nome do ficheiro que está a acção sobre não está disponível imediatamente.

Resolução

Uma solução para a acção 'Adicionar' consiste em comparar os itens do projecto da versão em questão com a versão anterior. O ficheiro está na versão actual e não na versão anterior é o ficheiro que foi adicionado.

Ponto Da Situação

A Microsoft confirmou que este erro ocorre nos produtos da Microsoft listados no início deste artigo.

Mais Informação

Passos para reproduzir o comportamento

NOTA: Este procedimento utiliza o Microsoft Visual Basic, mas o mesmo pode ser conseguido noutros idiomas.
  1. Crie um projecto EXE padrão no Visual Basic.
  2. Crie uma biblioteca de referência para o Microsoft SourceSafe 6.0 (ou 5.0) (Ssapi.dll).
  3. Adicione um botão de comando ao Form1.
  4. Faça duplo clique no botão.
  5. Cole o seguinte código de Sub Command1_Click:
    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. Execute o programa.
  7. Para implementar a solução acima mencionada, cole o seguinte (note que este é mais do que apenas o Sub Command1_Click):
    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. Execute o programa.

Referências

Para obter informações adicionais, visite o seguinte Web site da Microsoft:
Automatização do Visual SourceSafe 6.0
http://msdn.microsoft.com/en-us/library/bb509341.aspx (http://msdn.microsoft.com/en-us/library/bb509341.aspx)

A informação contida neste artigo aplica-se a:
  • Microsoft Visual SourceSafe 5.0 Standard Edition
  • Microsoft Visual SourceSafe 6.0 Standard Edition
Palavras-chave: 
kbmt kbautomation kbbug kbnofix KB248078 KbMtpt
Tradução automáticaTradução automática
IMPORTANTE: Este artigo foi traduzido por um sistema de tradução automática (também designado por Machine translation ou MT), não tendo sido portanto revisto ou traduzido por humanos. A Microsoft tem artigos traduzidos por aplicações (MT) e artigos traduzidos por tradutores profissionais. O objectivo é simples: oferecer em Português a totalidade dos artigos existentes na base de dados do suporte. Sabemos no entanto que a tradução automática não é sempre perfeita. Esta pode conter erros de vocabulário, sintaxe ou gramática? erros semelhantes aos que um estrangeiro realiza ao falar em Português. A Microsoft não é responsável por incoerências, erros ou estragos realizados na sequência da utilização dos artigos MT por parte dos nossos clientes. A Microsoft realiza actualizações frequentes ao software de tradução automática (MT). Obrigado.
Clique aqui para ver a versão em Inglês deste artigo: 248078  (http://support.microsoft.com/kb/248078/en-us/ )