Replace CodeDom with Roslyn but “bin\roslyn\csc.exe not found!”
Most of the .NET developers especially who tried to use C#6 or higher in ASPNET MVC might have faced this error and already know how to fix it, but don’t be so surprised if I tell you this article isn’t about ASPNET MVC it’s about WPF, WinForms or Console Applications!
CodeDom is about dynamic compilation at runtime. I have used it on several projects. For faster compilation and support version 6 or higher of C# we decided to replace CodeDom with Rosylin but due to backward compatibility and try not to make lots of changes on the code we used Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package.
Description from NuGet package:
Replacement CodeDOM providers that use the new .NET Compiler Platform (“Roslyn”) compiler as a service APIs. This provides support for new language features in systems using CodeDOM (e.g. ASP.NET runtime compilation) as well as improving the compilation performance of these systems.
So I only replaced System.CSharp.CSharpCodeProvider with DotNetCompilerPlatform.CSharpCodeProvider!
var compiler = new DotnetCompilerPlatform.CSharpCodeProvider(); // new CSharpCodeProvider
Built the solution and everything went fine but in the runtime when the app supposed to compile a dynamic…