title: How to compile a C# file with Roslyn programmatically?
body: <p>I read that you can't compile C# 6.0 with CSharpCodeProvider and therefor trying to do with with Roslyn. But I can't find a good example how to load a file and then compile it to a dll.</p>
  
  <p>How should I write something similar to this code with Roslyn? Or is there some other way to do it? Now when I try to compile files that contain reference to projects with C# 6.0 code it just say  "The type or namespace name 'x' does not exist in the namespace 'y' (are you missing an assembly reference?)"</p>
  
  <pre><code>    public string CompileCode()
      {
          var provider = new CSharpCodeProvider();
          var outputPath = Path.Combine(Path.GetDirectoryName(_path), $"Code.dll");
          var compilerparams = new CompilerParameters(_referencedAssemblies, outputPath);
          CompilerResults results = provider.CompileAssemblyFromFile(compilerparams, _path);
          var dllPath = results.PathToAssembly;
          if (!results.Errors.HasErrors)
              return dllPath;
          PrintError(results.Errors);
          return ""; 
      }
  </code></pre>
  
  <p>In summary I want to: </p>
  
  <ul>
  <li>Load a C# file</li>
  <li>Compile it to a dll so I can load it later.</li>
  </ul>