title: How to get the semantic model from source in Roslyn
body: <p>In all examples when using <a href="https://github.com/dotnet/roslyn" rel="noreferrer">Roslyn</a>, you have something like this:</p>
  
  <pre><code>SyntaxTree tree = CSharpSyntaxTree.ParseText(
  @"using System;
  using System.Collections.Generic;
  using System.Text;
  
  namespace HelloWorld
  {
      // A whole program here...
  }");
  
  var root = (CompilationUnitSyntax)tree.GetRoot();
  
  // Getting the semantic model (for MSCORELIB)
  var compilation = CSharpCompilation.Create("HelloWorld")
                    .AddReferences(
                       MetadataReference.CreateFromFile(
                         typeof(object).Assembly.Location))
                    .AddSyntaxTrees(tree);
  var model = compilation.GetSemanticModel(tree);
  </code></pre>
  
  <h2>How to get the semantic model for my code?</h2>
  
  <p>The last piece of code retrieves the semantic model for <code>mscorelib</code> types: <code>MetadataReference.CreateFromFile(typeof(object).Assembly.Location)</code> so that I can inspect <code>using</code>s or other parts of the source and get symbol information.</p>
  
  <p>But if I define types in <code>HelloWorld</code> and wanted to retrieve symbol info from those, I would the semantic model. But since I just loaded <code>mscorelib</code> I would not get this info.</p>
  
  <p>How to load the semantic model for the source I just defined?</p>