玩转C科技.NET

从学会做人开始认识这个世界!http://volnet.github.io

导航

如何批量下载VS2008中公开的微软源代码

首先要感谢微软公司在VS2008中引入了部分开源的协议使大家不必再通过Reflector等工具进行反编译,着实让大家感受到了不少便利。

不过微软的VS2008中的开源方式存在若干不足,最重要的不足之处在于它的查看方式。微软的做法是允许用户在调试项目的时候通过断点可以进入相关的源码进行查看。(具体配置等操作见:Shawn Burke's Blog《Configuring Visual Studio to Debug .NET Framework Source Code》或者ScottGu's Blog《.NET Framework Library Source Code now available》)。

这样方式的好处是用户不必一次性下载太多的代码,甚至有些根本永远用不到,也可以保证每次断点进来之后所得到的代码是最新的。但是这样的坏处在短期内却显而易见,就我个人经验来说,因为网络速度,特别是非美国国家可能在源代码服务器的访问速度上就更加地滞后了,因此所带来的结果就是第一次断点的时候将会导致长时间的延迟(包括访问服务器,以及从服务器下载相关文件,就以C#来说,则有pdb文件和cs文件两种,光是cs文件也就几K的大小,但是pdb文件通常上兆,再搭配上本来就不宽裕的网络环境以及并没有类似常规的多线程加速下载,这样的延迟将带来的用户体验是极差的。)虽然官方的说法是仅在第一次才会如此,但是这的确给了大家诸多不便。社区内顿时就提出了相关的想法和意见(见MSDN论坛上的相关版块)。

感谢Kerem KusmezerJohn Robbins在开源项目NetMassDownloader(http://www.codeplex.com/NetMassDownloader)中所做的贡献,通过一个控制台应用程序实现了批量下载(batch download)微软源代码的开源项目。以下源自John Robbins在项目文档中的部分文字:

It turns out I wasn’t the only one who had the same wishes. Kerem Kusmezer contacted me and said that he’d been hacking around with Fiddler and figured out how to download the PDBs and code from Microsoft. He asked if I I’d be interested in helping him develop the utility and I don’t think I ever wrote a response faster in my life! Kerem had already started a discussion with Shawn Burke about the legality of producing a source downloader and once we got back a very encouraging “go for it” we got to work. All the credit for the tool belongs to Kerem. He did all the really hard work of figuring out the HTTP downloads ,the PE file processing, and PDB Stream Extraction. I did the console driver, a lot of testing, and sat around amazed at how much work Kerem could accomplish in very short periods of time. I really appreciate that Kerem let me work on the project with him and being his code monkey.

许多朋友在使用该工具的时候出现了一些小问题,下面就以我最基本的使用方式列举一个比较简单的步骤,(在codeplex上有更多关于它的高级应用)。

步骤:

1、正确安装VS2008并确保我们已经按Shawn Burke's Blog《Configuring Visual Studio to Debug .NET Framework Source Code》进行了正确的配置。

2、假设我们将NetMassDownloader Release包解压到文件夹

C:\GoCoolCenter\MyCSharpProject\SampleCode\NetMassDownloader
我们就需要进入相关目录:
通过命令提示符(开始->运行->cmd),若解压包放在其他盘如F盘下,则先输入
F:

回车,然后cd F:\GoCoolCenter\MyCSharpProject\SampleCode\NetMassDownloader

这里我们由于在C盘则直接

cd C:\GoCoolCenter\MyCSharpProject\SampleCode\NetMassDownloader

这时运行:

NetMassDownloader -d "C:\Windows\Microsoft.NET\Framework\v2.0.50727" -v

很明显,-d之后是我们的.NET Framework的目录,这个可能需要根据我们的具体情况做出相应调整。

之后就可以看到类似以下的代码,这时不要关闭当前命令提示符框,并保持网络连接通畅即可。

以上总结为两句命令:

cd C:\GoCoolCenter\MyCSharpProject\SampleCode\NetMassDownloader

NetMassDownloader
-d "C:\Windows\Microsoft.NET\Framework\v2.0.50727" -v
.NET Framework 3.0和.NET Framework 3.5版本的下载代码如下
cd C:\GoCoolCenter\MyCSharpProject\SampleCode\NetMassDownloader
netmassdownloader -d "C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5" -d "c:\program files\Reference Assemblies\Microsoft\Framework\v3.0"


下载后的文件将保存在VS2008中设置的相应目录:

symbols_setting

按照NetMassDownloader的说明,经过设置后该源代码还可用于VS2005的使用。

posted on 2008-02-18 23:52  volnet(可以叫我大V)  阅读(2991)  评论(3编辑  收藏  举报

使用Live Messenger联系我
关闭