Visual Studio:打印解决方案中的所有源文件? [英] Visual Studio: Printing all source files in a solution?

查看:143
本文介绍了Visual Studio:打印解决方案中的所有源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以一次打印解决方案中的所有(* .cs)文件,也就是说,无需单击每个文件然后单击打印?

Is there a way to print all (*.cs) files in a solution at once, that is, without clicking on each of them and then hitting print?

推荐答案

根据我从在其他地方问过类似的问题,此功能"未内置到Visual Studio中.

From what I gather from a similar question asked elsewhere, this "feature" is not build into Visual Studio.

但是,它看起来像 MSDN具有可用于打印所有内容的宏代码;也许您可以使用它或类似的东西:

However it looks like MSDN has a macro you can use to print all of your code; perhaps you can use this, or something like it:

Sub PrintItemsInSelectedProject()
    Dim proj As Project
    Dim objProj As Object()

    objProj = DTE.ActiveSolutionProjects
    If objProj.Length = 0 Then
        Exit Sub
    End If
    proj = DTE.ActiveSolutionProjects(0)
    PrintItemsInSelectedProject(proj.ProjectItems)
End Sub

Private Sub PrintItemsInSelectedProject( _
    ByVal projitems As ProjectItems)
    Dim projitem As ProjectItem

    For Each projitem In projitems
        If (IsPrintableFile(projitem) = True) Then
            If (projitem.IsOpen( _
                    EnvDTE.Constants.vsViewKindTextView)) Then
                projitem.Document.PrintOut()
            Else
                Dim doc As Document
                doc = projitem.Open( _
                    EnvDTE.Constants.vsViewKindTextView).Document
                doc.PrintOut()
                doc.Close(vsSaveChanges.vsSaveChangesNo)
            End If
        End If
        PrintItemsInSelectedProject(projitem.ProjectItems)
    Next
End Sub

Function IsPrintableFile( _
        ByVal projItem As ProjectItem) As Boolean
    Dim fileName As String
    Dim extensions As _
        New System.Collections.Specialized.StringCollection
    ' If you add a file to your project that is of 
    ' a type that can be printed, 
    ' then add the extension of that 
    ' file type to this list.
    Dim exts As String() = {".cs", ".vb", _
        ".aspx", ".xsd", ".xml", ".xslt", _
        ".config", ".htm", ".html", ".css", _
        ".js", ".vbs", ".wsf", ".txt", ".cpp", _
        ".c", ".h", ".idl", ".def", ".rgs", ".rc"}

    extensions.AddRange(exts)
    fileName = projItem.FileNames(1)
    Return extensions.Contains( _
        System.IO.Path.GetExtension(fileName).ToLower())
End Function

这篇关于Visual Studio:打印解决方案中的所有源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆