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

后端 未结 3 1833
野趣味
野趣味 2021-01-13 03:15

Visual Studio no longer supports macros, so the answer in the following question is only valid for previous releases:

Report error/warning if missing files in projec

3条回答
  •  醉酒成梦
    2021-01-13 03:35

    Based on VS macro code you referenced, I've created an extension for Visual Commander to report warning:

    Imports EnvDTE
    Imports EnvDTE80
    
    Public Class E
        Implements VisualCommanderExt.IExtension
    
        Sub SetSite(DTE_ As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.IExtension.SetSite
            DTE = DTE_
            events = DTE.Events
            buildEvents = events.BuildEvents
            AddHandler buildEvents.OnBuildBegin, AddressOf OnBuildBegin
        End Sub
    
        Sub Close() Implements VisualCommanderExt.IExtension.Close
            RemoveHandler buildEvents.OnBuildBegin, AddressOf OnBuildBegin
        End Sub
    
        Private Sub OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction)
            For Each proj As Project In DTE.Solution.Projects
                For Each item As ProjectItem In proj.ProjectItems
                    If (item.Kind <> "{6BB5F8EE-4483-11D3-8BCF-00C04F8EC28C}") Then ' only check physical file items
                        Continue For
                    End If
    
                    For i As Integer = 1 To item.FileCount
                        Dim path As String = item.FileNames(i)
                        If Not System.IO.File.Exists(item.FileNames(i)) Then
                            WriteToBuildWindow("!! Missing file:" & item.FileNames(i) + " in project " + proj.Name)
                        End If
                    Next
                Next
            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 & System.Environment.NewLine)
        End Sub
    
        private DTE As EnvDTE80.DTE2
        private events As EnvDTE.Events
        private buildEvents as EnvDTE.BuildEvents
    
    End Class
    

提交回复
热议问题