Report error/warning if missing files in project/solution in Visual Studio

后端 未结 4 1671
谎友^
谎友^ 2020-12-31 11:45

Is there a way for Visual Studio to report an error/warning when you build a solution that has missing files (yellow triangle icon with exclamation) that do have necessarily

4条回答
  •  忘掉有多难
    2020-12-31 12:03

    When we had missing files, we were getting crazy compile errors, like unable to write xyz.pdb even though the file ended up getting written. I took what Simon had provided (thanks!) and flipped it around a bit; specifically, I added a bit of recursion and added support for folders and files with sub-files (e.g. datasets, code-behinds).

    Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
    
        For Each proj As Project In DTE.Solution.Projects
            walkTree(proj.ProjectItems, False)
        Next
    
    End Sub
    
    Private Sub walkTree(ByVal list As ProjectItems, ByVal showAll As Boolean)
    
        For Each item As ProjectItem In list
    
            ' from http://msdn.microsoft.com/en-us/library/z4bcch80(v=vs.80).aspx
            ' physical files:   {6BB5F8EE-4483-11D3-8BCF-00C04F8EC28C}
            ' physical folders: {6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}
    
            If (item.Kind = "{6BB5F8EE-4483-11D3-8BCF-00C04F8EC28C}" OrElse _
                item.Kind = "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}") Then
    
                For i As Integer = 1 To item.FileCount ' appears to be 1 all the time...
    
                    Dim existsOrIsFolder As Boolean = (item.Kind = "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}" OrElse System.IO.File.Exists(item.FileNames(i)))
    
                    If (showAll OrElse _
                        existsOrIsFolder = False) Then
    
                        WriteToBuildWindow(String.Format("{0}, {1}, {2} ", existsOrIsFolder, item.ContainingProject.Name, item.FileNames(i)))
    
                    End If
    
                Next
    
                If (item.ProjectItems.Count > 0) Then
                    walkTree(item.ProjectItems, showAll)
                End If
    
            End If
    
        Next
    
    End Sub
    
    Private Sub WriteToBuildWindow(ByVal text As String)
        Dim ow As OutputWindow = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object
        Dim build As OutputWindowPane = ow.OutputWindowPanes.Item("Build")
        build.OutputString(text & Environment.NewLine)
    End Sub
    

提交回复
热议问题