• Stars
    star
    1,026
  • Rank 43,108 (Top 0.9 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Source browser website generator that powers http://referencesource.microsoft.com and http://sourceroslyn.io

SourceBrowser

NuGet package

Source browser website generator that powers https://referencesource.microsoft.com, http://sourceroslyn.io, https://source.dot.net, and others.

Create and host your own static HTML website to browse your C#/VB/MSBuild/TypeScript source code. Note that it does require an ASP.NET Core website for hosting (symbol index is kept server-side), so without ASP.NET Core the search function doesn't work.

Of course Source Browser allows you to browse its own source code: http://sourcebrowser.azurewebsites.net

Now also available on NuGet: https://www.nuget.org/packages/SourceBrowser

Instructions to Build (requires Visual Studio 2019):

  1. git clone https://github.com/KirillOsenkov/SourceBrowser
  2. cd SourceBrowser
  3. Build.cmd

Instructions to generate and run a test website

  1. GenerateTestSite.cmd
  2. RunTestSite.cmd

In Visual Studio 2019:

  1. Open SourceBrowser.sln.
  2. Set HtmlGenerator project as startup and hit F5 - it is preconfigured to generate a website for TestCode\TestSolution.sln.
  3. Pass a path to an .sln file or a .csproj file (or multiple paths separated by spaces) to create an index for them
  4. Pass /out: to HtmlGenerator.exe to configure where to generate the website to. This path will be used in step 6 as your "physicalPath".
  5. Pass /in: to pass a file with a list of full paths to projects and solutions to include in the index
  6. Pass /root: if you want to preserve relative .sln folders rather than merging all solutions. This folder must contain all specified .sln or .csproj paths.
  7. Set SourceIndexServer project as startup and run/debug the website.

Note: Visual Studio 2019 is required to build Source Browser.

Conceptual design

At indexing time, C# and VB source code is analyzed using Roslyn and a lot of static hyperlinked HTML files are generated into the output directory. There is no database. The website is mostly static HTML where all the links, source code coloring etc. are precalculated at indexing time. All the hyperlinks are hardwired to be simple links bypassing the server.

The only component that runs on the webserver is a service that given a search query does the lookup and returns a list of matching types and members, which are hyperlinks into the static HTML. The webservice keeps a list of all declared types and members in memory, this list is also precalculated at indexing time. All services, such as Find All References, Project Explorer, etc. are all pre-rendered.

The generator is not incremental. You have to generate into an empty folder from scratch every time, and then replace the currently deployed folder with the new contents atomically (using e.g. Azure Deployments, robocopy /MIR to inetpub\wwwroot, etc). For smaller projects, deploying to Azure using Dropbox or Git would work just fine.

Limitations and known issues

  1. Indexing more than one project with the same assembly name is currently unsupported. Only the first project wins. This is due to a fundamental design decision to only reference an assembly by short name. Customizers should add a means to filter "victim" projects out in their forks to pick the best single project for inclusion in the index.
  2. The generated website can only be hosted in the root of the domain. Making it run from a subdirectory is non-trivial and unlikely to be supported.

Features

  • Solution Explorer - contents of projects merged into single tree on the left
  • coloring for C#, VB, MSBuild, XAML and TypeScript
  • Go To Definition (click on a reference)
  • Find All Reference (click on a definition)
  • Project Explorer - in any document click on the Project link at the bottom
  • Namespace explorer - for a project view all types and members nested in namespace hierarchy
  • Document Outline - for a document click on the button in top right to display types and members in the current file
  • http://<URL>/i.txt for the entire solution and /AssemblyName/i.txt (for an assembly) displays source code stats, lines of code, etc
  • http://<URL>/#EmptyArrayAllocation finds all allocations of empty arrays (this feature is one-off and hardcoded and not extensible)
  • Clicking on the partial keyword will display a list of all files where this type is declared
  • MSBuild files (.csproj etc) have hyperlinks
  • TypeScript files (*.ts) are indexed if they're part of a C# project. Work underway to allow an arbitrary array of TypeScript files.
  • Search for GUIDs in C#/VB string literals is supported

Project status and contributions

This is a reference implementation that showcases the concepts and Roslyn usage. It comes with no guarantees, use at your own risk. We will consider accepting high-quality pull requests that add non-trivial value, however we have no plans to do significant work on the application in its current form. Any significant rearchitecture, adding large features, big refactorings won't be accepted because of resource constraints. Feel free to use it to generate websites for your own code, integrate in your CI servers etc. Feel free to do whatever you want in your own forks. Bug reports are gratefully accepted.

For any questions, feel free to reach out to @KirillOsenkov on Twitter. Thanks to @v2_matveev for contributing TypeScript support! Thanks to numerous other contributors for various fixes and contributions!

More Repositories

1

MSBuildStructuredLog

A logger for MSBuild that records a structured representation of executed targets, tasks, property and item values.
C#
1,364
star
2

RoslynQuoter

Roslyn tool that for a given C# program shows syntax tree API calls to construct its syntax tree
C#
822
star
3

XmlParser

A Roslyn-inspired full-fidelity XML parser with no dependencies and a simple Visual Studio XML language service
C#
316
star
4

MetadataTools

Various tools and helpers to read assembly metadata.
C#
173
star
5

QuickInfo

http://quickinfo.io - a search textbox with extensible "answers" (calculator, unit-converter, colors, ascii/unicode, etc). See demo at http://quickinfo.io/?demo
C#
158
star
6

CodeCleanupTools

A set of command-line tools to cleanup C# and VB source code.
C#
121
star
7

Undo

Simple .NET Undo/Redo framework with merging and transactions
C#
102
star
8

ContentSync

Directory copy/sync/mirror tool that uses file contents (not timestamps) to avoid touching identical files
C#
61
star
9

LargeAddressAware

A build tools package that adds support for making 32-bit exes LARGEADDRESSAWARE
C#
51
star
10

LayoutDesigner

A prototype Silverlight UI layout designer. Works with basic panels (StackPanel and Grid). Built entirely using drag-n-drop. XAML can be copied to clipboard. Built with Silverlight 4 and runs in the browser.
C#
48
star
11

StructuredEditor

An experimental structured code editor prototype for a subset of C#
C#
47
star
12

Bliki

Blog/Wiki/Notes
30
star
13

LiveGeometry

Interactive geometry CAD-like educational software
Visual Basic 6.0
28
star
14

MathParser

Parser for arithmetic expressions
C#
21
star
15

MEFMetadata

Metadata-based part discovery for MEF, uses the Roslyn metadata reader and is faster than reflection.
C#
18
star
16

MSBuildLog

Source code for http://msbuildlog.com
HTML
15
star
17

Benchmarks

My collection of benchmarks for random pieces of code
C#
13
star
18

NuGetTools

C#
13
star
19

WpfSendKeys

SendKeys for WPF
C#
10
star
20

DumpTools

Tools to analyze managed .dmp files using ClrMd
C#
8
star
21

MEFTools

Tools to help working with MEF
C#
7
star
22

Misc

Various small and one-off projects just barely too big to throw away
C#
6
star
23

Dia2Dump

Taken from C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\DIA SDK\Samples\DIA2Dump
C++
6
star
24

dotfiles

My dotfiles and Mac config
Shell
3
star
25

MyOwnSearchEngine

This repo has moved to https://github.com/KirillOsenkov/QuickInfo
JavaScript
3
star
26

DiagnosticMargin

C#
3
star
27

VSInstanceFinder

Finds the locations of all installed VS 2017 instances
C#
2
star
28

ColorTools

JavaScript
2
star
29

MagicSquare

Simple addition/multiplication table for kids
C#
2
star
30

MefHost

Test MEF host to repro a bug
C#
1
star
31

ApplyPatch

Simple utility to apply a patch to a set of files
C#
1
star
32

guilabs

Source code for http://guilabs.net
HTML
1
star
33

BeachballPoker

C#
1
star