如果在Visual Studio 2012/2013中的项目/解决方案中缺少文件,则报告错误/警告
问题描述:
Visual Studio 不再支持宏,因此以下问题的答案仅对以前的版本有效:
Visual Studio no longer supports macros, so the answer in the following question is only valid for previous releases:
报告错误/警告Visual Studio项目/解决方案中缺少文件
在构建缺少文件的解决方案时,Visual Studio 2012/2013是否可以报告错误/警告?
Is there a way for Visual Studio 2012 / 2013 to report an error/warning when you build a solution that has missing files?
答
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