visual-studio Visual Studio:打印解决方案中的所有源文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/683759/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio: Printing all source files in a solution?
提问by Dervin Thunk
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?
有没有办法一次打印解决方案中的所有 (*.cs) 文件,也就是说,无需单击每个文件然后点击打印?
采纳答案by Daniel LeCheminant
From what I gather from a similar question asked elsewhere, this "feature" is not build into Visual Studio.
从我从其他地方提出的类似问题中收集的信息来看,这个“功能”没有内置到 Visual Studio 中。
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:
但是看起来MSDN 有一个可以用来打印所有代码的宏;也许你可以使用这个,或者类似的东西:
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
回答by Dror Harari
Putting aside the fun comments from tree-huggers, let's assume you want to printout the Visual Studio solution as PDF (and we won't ask what you do with it later).
暂且不提那些来自拥抱树木的人的有趣评论,假设您想将 Visual Studio 解决方案打印为 PDF(我们稍后不会问您用它做什么)。
For people who use VisualStudio there is a very nice program that used to be sold but is now available to download for free, called PrettyCode.Print for .NET 2.0. It is available for download here(the company retiredthe product).
对于使用 VisualStudio 的人来说,有一个非常好的程序,曾经出售但现在可以免费下载,称为 PrettyCode.Print for .NET 2.0。可在此处下载(该公司已停用该产品)。
It reads in a VisualStudio project (works with VS2005, VS2008 and VS2010) and let one print a selection of files with various printing options. It does a pretty decent job.
它读入一个 VisualStudio 项目(适用于 VS2005、VS2008 和 VS2010)并让一个人使用各种打印选项打印一系列文件。它做得相当不错。
回答by Djeison
You can download PrettyCode.Print for .NET 2.0 (VS2008 and VS2005) in:http://pan.baidu.com/wap/shareview?&shareid=3968547697&uk=286220058&dir=%2FSoftz&page=1&num=20&fsid=1117386981714891&third=0In my computer work fine with Visual Studio 2013.
您可以下载PrettyCode.Print为.NET 2.0(VS2008和VS2005)在:http://pan.baidu.com/wap/shareview?&shareid=3968547697&uk=286220058&dir=%2FSoftz&page=1&num=20&fsid=1117386981714891&third=0在我的电脑使用 Visual Studio 2013 工作正常。

