首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Visual Studio:打印解决方案中的所有源文件?

Visual Studio:打印解决方案中的所有源文件?
EN

Stack Overflow用户
提问于 2009-03-25 22:24:14
回答 4查看 31K关注 0票数 21

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

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2009-03-25 22:51:40

从我从a similar question asked elsewhere收集到的信息来看,这个“特性”并没有内置到Visual Studio中。

尽管它看起来像MSDN has a macro you can use to print all of your code;也许您可以使用下面的代码,或者使用类似的代码:

代码语言:javascript
复制
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
票数 10
EN

Stack Overflow用户

发布于 2012-01-25 06:56:21

抛开拥树者的有趣评论不谈,让我们假设您想要将Visual Studio解决方案打印为PDF (稍后我们不会问您如何处理它)。

对于使用VisualStudio的人来说,有一个非常好的程序,以前是出售的,但现在可以免费下载,叫做.NET 2.0的PrettyCode.Print。它可以从( retired here产品的公司)下载。

它读取VisualStudio项目(适用于VS2005、VS2008和VS2010),并允许用户使用各种打印选项打印选定的文件。它做了一个相当不错的工作。

票数 7
EN

Stack Overflow用户

发布于 2015-04-11 00:11:58

你可以在我的电脑中下载用于.NET 2.0的PrettyCode.Print (VS2008和VS2005):http://pan.baidu.com/wap/shareview?&shareid=3968547697&uk=286220058&dir=%2FSoftz&page=1&num=20&fsid=1117386981714891&third=0 In my computer work fine with Visual Studio2013。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/683759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档