gpt4 book ai didi

visual-studio - 如果 Visual Studio 2012/2013 中的项目/解决方案中缺少文件,则报告错误/警告

转载 作者:行者123 更新时间:2023-12-04 17:35:35 25 4
gpt4 key购买 nike

Visual Studio no longer supports macros ,因此以下问题中的答案仅适用于以前的版本:

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

当您构建缺少文件的解决方案时,Visual Studio 2012/2013 有没有办法报告错误/警告?

最佳答案

我修改了 Sergey 的脚本来递归处理文件夹。

更新:为每个项目添加了一个消息框弹出窗口,其中列出了 Thomas Svensen 在评论中建议的丢失文件

更新 2:现在将丢失的文件写入输出窗口并作为错误列表中的错误。这不会导致构建失败,只是错误列表中的一行。

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
Dim missingFiles As String = ""
For Each item As ProjectItem In proj.ProjectItems
missingFiles = missingFiles + CheckProjectItem(item, proj)
Next
If missingFiles.Length > 0 Then
' comment out to remove message box popup and only have missing files listed in output / error windows
System.Windows.MessageBox.Show("Project " + proj.Name + " missing files:" + System.Environment.NewLine + missingFiles)
End If
Next
End Sub

Private Function CheckProjectItem(ByVal item As EnvDTE.ProjectItem, ByVal proj As EnvDTE.Project)
Dim missingFiles As String = ""
For Each chiltItem As ProjectItem In item.ProjectItems
missingFiles = missingFiles + CheckProjectItem(chiltItem, proj)
Next

If (item.Kind = "{6BB5F8EE-4483-11D3-8BCF-00C04F8EC28C}") Then ' only check physical file items
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
LogMissingFile(item.FileNames(i), proj.Name)
missingFiles = missingFiles + item.FileNames(i) + System.Environment.NewLine
End If
Next
End If
Return missingFiles
End Function

Private Sub LogMissingFile(ByVal fileName As String, ByVal projectName As String)
Dim ow As OutputWindow = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object
Dim build As OutputWindowPane = ow.OutputWindowPanes.Item("Build")
Dim outputString As String = "!! Missing file: " + fileName + " in project " + projectName + System.Environment.NewLine
Dim errorString As String = "Missing file in project " + projectName + ": " + fileName
' write to ONLY the Output window
' build.OutputString(outputString)
' write to BOTH Output and Error window; vsTaskPriorityHigh will show as error, vsTaskPriorityMedium as warning, and vsTaskPriorityLow as message
build.OutputTaskItemString(outputString, vsTaskPriority.vsTaskPriorityHigh, vsTaskCategories.vsTaskCategoryMisc, vsTaskIcon.vsTaskIconCompile, fileName, 0, errorString)
End Sub

private DTE As EnvDTE80.DTE2
private events As EnvDTE.Events
private buildEvents as EnvDTE.BuildEvents

End Class

关于visual-studio - 如果 Visual Studio 2012/2013 中的项目/解决方案中缺少文件,则报告错误/警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20689829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com