title: Roslyn: Effect of CSharpCompilerOptions WithUsings
body: <p>My question is about <code>CSharpCompilerOptions</code> and <code>using</code> statements passed to an instance of <code>CSharpCompilation</code>. </p>
  
  <p>I have a syntax tree parsed from some text:</p>
  
  <pre><code>SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(@"
              namespace RoslynCodeAnalysis
              {
                  using System;
                  using System.Net; // Commenting this out causes errors
  
                  public class Writer
                  {
                      public void Write(string message)
                      {
                          WebClient client = new WebClient();
                          Console.WriteLine(message); 
                      }
                  }
              }");
  </code></pre>
  
  <p>The CSharpCompilation instance is created as below. I did not include the references for simplicity but it does add a reference to System.Net and few other common assemblies.</p>
  
  <pre><code>CSharpCompilation compilation = CSharpCompilation.Create(
              assemblyName,
              syntaxTrees: new[] { syntaxTree },
              references: references,
              options: new CSharpCompilationOptions(
                         OutputKind.DynamicallyLinkedLibrary, 
                         usings: new List&lt;string&gt; { "System", "System.Net" }));
  </code></pre>
  
  <p>The issue is that, if I comment out using System.Net, I get errors saying that:</p>
  
  <blockquote>
    <p>CS0246: The type or namespace name 'WebClient' could not be found (are
    you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>What could cause this? The options passed to CSharpCompilation has the usings property set to System and System.Net. Is this the normal behavior or am I missing something? Even though the usings property is specified, source text still needs to have the using statement? I am pretty sure I am missing something!</p>