有没有办法一次打印解决方案中的所有(*.cs)文件,也就是说,没有点击它们然后点击打印?
从我从其他地方提出的类似问题中收集的内容来看,这个"功能"并没有构建到Visual Studio中.
但是看起来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
暂且不谈树抱抱的有趣评论,让我们假设你想要将Visual Studio解决方案打印成PDF(我们不会问你以后用它做什么).
对于使用VisualStudio的人来说,有一个非常好的程序曾经被出售但现在可以免费下载,名为PrettyCode.Print for .NET 2.0.它可以在这里下载(公司退役了产品).
它读入VisualStudio项目(与VS2005,VS2008和VS2010配合使用),然后打印一系列带有各种打印选项的文件.它做得相当不错.