title: Build with Roslyn, but leave the "compile-at-runtime" executables at the door?
body: <p>There has been a lot of talk about the C# compiler <a href="https://www.safaribooksonline.com/library/view/c-60-in/9781491927090/ch27.html#whatapostrophes_new_in_chash_6dot0" rel="noreferrer">Roslyn</a> on <em>StackOverflow</em> and the internet in general. A lot of people ask <a href="https://stackoverflow.com/questions/33740123/what-why-is-roslyn-needed-in-bin-folder-of-asp-net">what and why</a> with Roslyn, while others ask how to <a href="https://stackoverflow.com/questions/32282880/publish-website-without-roslyn">get rid of it</a>.</p>
  
  <p>My question pertains to the latter question. As quoted from <em>Kemal Kefeli</em> from <a href="https://stackoverflow.com/questions/32282880/publish-website-without-roslyn">here</a>, but frequently iterated verbatim by dozens more (e.g. <a href="https://stackoverflow.com/questions/32648369/what-is-the-possible-solution-if-the-asp-net-hosting-provider-does-not-allow-ex?rq=1">another example</a> of iteration), in order to remove Roslyn:</p>
  
  <blockquote>
    <p>When you create a new web project, two <em>NuGet</em> packages automatically added to your project. If you remove them, your problem should be solved. Package names are: "<strong>Microsoft.CodeDom.Providers.DotNetCompilerPlatform</strong>" and "<strong>Microsoft.Net.Compilers</strong>".</p>
  </blockquote>
  
  <p>This approach, however, does not work if you are using the C# 6 features that Roslyn offers. By removing these two nugget packages, you give up any chance of using these features.</p>
  
  <p>My question is, how do you compiler everything with Roslyn, but avoid having any compiler-at-runtime actions occurring and most importantly, the <code>csc.exe</code>, <code>vbc.exe</code>, and <code>VBCSCompiler.exe</code> from being placed in the final release version (in the Roslyn folder).</p>
  
  <p>I am porting over <em>StackOverflow's</em> <strong><a href="https://github.com/opserver/Opserver" rel="noreferrer">Opserver</a></strong> into a piece of software. The software allows users to host embedded web servers and web pages from within it. However, the software is very picky about what it allows to be uploaded and executables, like those found in the Roslyn folder, are <strong>not</strong> allowed to be uploaded and executed at runtime due to security reasons.</p>
  
  <p><strong><a href="https://github.com/opserver/Opserver" rel="noreferrer">Opserver</a></strong> relies on C# 6 features, because if I remove those two <em>NuGet</em> packages, errors sprout up in compile-generated files. But, if I more simply revert to <a href="https://www.codeproject.com/tips/865579/how-to-change-targeted-csharp-version-in-visual-st" rel="noreferrer">compile strictly with</a> the C#5.0 compiler, then we see this clearly:</p>
  
  <p><a href="https://i.stack.imgur.com/W2y9R.png" rel="noreferrer"><img src="https://i.stack.imgur.com/W2y9R.png" alt="5.0 errors## Heading ##"></a></p>
  
  <p>If I leave the <em>NuGet</em> packages present and uncheck <code>allow precompiled site to be updatable</code> when publishing, in order to disallow Roslyn with compiling files at runtime as followed by <em>Rutix</em>'s comment from <a href="https://stackoverflow.com/questions/32282880/publish-website-without-roslyn">here</a>:</p>
  
  <blockquote>
    <p>Keep in mind that removing these packages [as told by <em>Kemal Kefeli</em>] will break the use of C# 6 features. This could be solved by unchecking "Allow precompiled site to be updatable" which pre-compiles the views ect.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/1ieR2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1ieR2.png" alt="Don&#39;t compiler at runtime"></a></p>
  
  <p>It still generates the executables and the associated DLLs in the Roslyn folder, however significantly less DLLs. How can I possibly remove the Roslyn dependency at runtime and therefore the executables from the outputted version and strictly compile <strong>everything</strong> at compile-time?</p>