I have the following piece of code in .NET Framework 4.8,
sourceCode = $@"
using System;
{string.Format(Constants.Assembly.UsingDirective, Constants.Assembly.DapperNamespace)}
namespace {Constants.Assembly.DynamicTypeNamespace} {{
{sourceCode}
}}";
// Create Compilation Parameters
CompilerParameters compileParams = new CompilerParameters()
{
CompilerOptions = Constants.Assembly.CompileToLibrary,
GenerateInMemory = true
};
compileParams.ReferencedAssemblies.AddRange(baseAssemblyLocations.ToArray());
// Create Code Provider
CSharpCodeProvider provider = new CSharpCodeProvider(new Dictionary<string, string>() {
{ Constants.Assembly.CompilerVersion, Constants.Assembly.CompilerVersion4 }
});
// Attempt compilation
CompilerResults compileResult = provider.CompileAssemblyFromSource(compileParams, sourceCode);
if (compileResult.Errors.Count > 0)
{
throw new Exception(compileResult.Errors[0].ErrorText);
}
// Store the assembly
Assembly = compileResult.CompiledAssembly;
I am looking into Roslyn APIs, but can't get it working using CSharpCompilationOptions.
How should I pass compilerParams, and sourceCode to the CSharpCompilationOptions
?