Microsoft has really helped out the development community by making the .NET Reference Source Code available to the community. Being able to step in the debugger from your code to the Framework code truly helps with you understanding and use of all parts of .NET. The only drawback I've seen with what Microsoft is offering is that the source code can only be downloaded while you're debugging. This means that unless you write a sample program that calls literally every class and method in the .NET Framework, you won't get all the source. As Scott Hanselman has so excellently pointed out, reading code is as important, if not more, than writing it. What I really wanted was a way to download all the .NET Reference Source so I could just start reading everything. Additionally, I wanted to fill my download cache with all the source so I had it all even when I didn't have a network connection.
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.
The tool is called Net Mass Downloader and we made the source code available at CodePlex at http://www.codeplex.com/NetMassDownloader so you can see how it works. It's a command line tool and running the tool without parameters produces the following output:
.Net Mass Downloader 18.104.22.168 - (c) 2008 by Kerem Kusmezer, John Robbins
Batch download the Microsoft .NET Reference Source code.
Usage: NetMassDownloader [-file <file>]
[-force] [-nologo] [-verbose] [-?]
-file - Download an individual file's PDB and source code. You can
specify multiple file parameters. (Short -f).
-directory - Download all the found PDB and source code for all files in
the specified directory. You can specify multiple
directory parameters (Short -d).
-output - The output directory for PDB and source files. The default
directory is the cache directory set in Visual Studio 2008.
By using the cache directory, you'll have the PDB and source
files available to Visual Studio 2008. However, to use the
.NET Reference Source Code with VS 2005, use the -output
switch and in the Options dialog, Debugging, Symbols property
page, add the specified output directory to the "Symbol file
(.pdb) locations." Also, add the directory to the Solution
Properties, Common Properties, Debug Source Files, Directories
containing source code location. The Visual Studio 2005
debugger will automatically load the source code. (Short -o)
-vsver - The Visual Studio version number to use for finding the cache
directory. The default is Visual Studio 2008,
but if you want to use the cache directory for Visual Studio
2005, you would pass '-vsver 8.0' (without quotes) (Short -vs)
-force - If specified, forces the downloading the PDB files into the
symbol server. When downloading to a symbol server if the PDB
exists, it's not downloaded. Using the -output switch will
always download and process the PDB. (Short -fo)
-nologo - Don't show the logo information. (Short -n)
-verbose - Do verbose output. May be worth turning on as the downloading
source code can take a long time. (Short -v)
-? - This help message..
The only required arguments are –file or –directory, both of which can be specified as many times as you'd like. When you specify a directory, only the .DLL and .EXE files from that directory will be processed. If you wanted to download all the source code from binaries in the .NET 2.0 32-bit and 64-bit directories, the command line you'd pass is: -d C:\Windows\Microsoft.NET\Framework\v2.0.50727 –d C:\Windows\Microsoft.NET\Framework64\v2.0.50727.
The main purpose of Net Mass Downloader is to populate the source code download cache for debugging, the default download location is the cache you specified to Visual Studio 2008. We put in the –vsver switch to account for future Visual Studio versions so Mass Downloader could work with future CTPs and versions.
While it's great to see the .NET Reference Source Code in Visual Studio 2008, there are a lot of developers out there who can't upgrade yet. Initially, Kerem and I went down the path of seeing if we could patch the PDB files so Visual Studio 2005 users could have access to the .NET Reference Source Code. After a lot of hassle, we realized that there was a much easier way. If you specify the –output switch, we will put the PDB and the source code into that directory using the build paths instead of the source server paths. Thus, if your command line to NetMassDownloader.exe is –d C:\Windows\Microsoft.NET\Framework\v2.0.50727 –output c:\ReferenceSource, the PDB files are put in C:\ReferenceSource as well as the source files.
To use the .NET Reference Source with Visual Studio 2005, you would need to do the following three additional steps. The first is in the Options dialog for Visual Studio, Debugging, Symbols property page. In the "Symbol file (.pdb) locations" list box, you would add "c:\ReferenceSource" like the following.
The second setting is in Options dialog, Debugging, General property page, uncheck Require source files to exactly match the original version.
The final step you'll have to do in each solution where you want to access the downloaded .NET Reference Source Code, you'll go into the solution property pages, Common Properties, Debugging Source Files, and add C:\ReferenceSources to the top of the "Directories containing source code" list box as follows:
Visual Studio 2005 will automatically do the right thing and replace the first directory of every source file it finds in a PDB file with c:\ReferenceSource. With the automation model in Visual Studio 2005, I'm sure you could wipe up a macro to automatically set that path in the solution.
When you first run Net Mass Downloader, you will be prompted with the current EULA for accessing the source code. If you don't agree with the Microsoft EULA, clicking the Decline button will not download the source code. While you might be tempted to remove the EULA check, I would strongly recommend that you not do so as Microsoft has said that they may change the EULA at any time. The last thing you want to do is get caught with a license change that could impact your life.
One group we need to thank is the Developer Division at Microsoft. First they released the .NET Reference Source Code, and second for allowing a couple of developers to have some fun and provide a utility for the community.
As always let us know on CodePlex if you encounter any bugs or have feature requests.On Feb 5 2008 4:55 PMBy jrobbins With 71 Comments