CodeCompiler
Compiler utility class for C# and VB compilation. Although you can technically re-use the same CodeCompiler instance to compile consecutive bits of source, we highly recommend creating a new instance for every new compile job. This class leverages the Roslyn compiler behind the scenes.
Constructors
Properties
GenerateInMemory
#Gets whether the assembly ought to be compiled in memory. This returns true when OutputPath is not set.
GetCachedAssembly
#Gets the assembly that was cached during the most recent compilation. This field may be null if no compilation has occured, if the most recent compilation failed, or it the most recent compilation generated an assembly on the disk.
GetCachedSemanticModels
#Gets the collection of semantic models (one for every syntax tree) that were cached during the most recent compilation. This property may yield an empty array if no compilation has occured yet, or if the most recent compilation failed.
GetCachedSyntaxTrees
#Gets the collection of syntax trees that were cached during the most recent compilation. This property may yield an empty array if no compilation has occured yet.
GetCachedWarnings
#Gets the collection of compiler warnings cached during the most recent compilation.
StandardAssemblies
#Enumerate over all assembly locations which are included by default in a compiled assembly.
StandardReferences
#Enumerate over all assembly references which are included by default in a compiled assembly.
Methods
AddReferenceAssembly
#Add an assembly location to be referenced in the build.
Parameters:
| path (string) | Assembly file location. |
Returns: True if assembly was added, false if it was already present.
CompileCSharpCode
#public Assembly CompileCSharpCode(IEnumerable<string> code, out CodeDiagnostic[] warnings, out CodeDiagnostic[] errors)
Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
Parameters:
| code (IEnumerable<string>) | Code to compile. |
| warnings (out CodeDiagnostic[]) | Code warnings, if any. |
| errors (out CodeDiagnostic[]) | Code errors, if any. |
CompileCSharpCode
#public Assembly CompileCSharpCode(IEnumerable<SyntaxTree> code, out CodeDiagnostic[] warnings, out CodeDiagnostic[] errors)
Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
Parameters:
| code (IEnumerable<SyntaxTree>) | Code to compile. |
| warnings (out CodeDiagnostic[]) | Code warnings, if any. |
| errors (out CodeDiagnostic[]) | Code errors, if any. |
CompileCSharpCode
#public Assembly CompileCSharpCode(string code, out CodeDiagnostic[] warnings, out CodeDiagnostic[] errors)
Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
Parameters:
| code (string) | Code to compile. |
| warnings (out CodeDiagnostic[]) | Code warnings, if any. |
| errors (out CodeDiagnostic[]) | Code errors, if any. |
CompileCSharpCode
#Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
Parameters:
| code (string) | Code to compile. |
CompileCSharpCode
#public Assembly CompileCSharpCode(SyntaxTree code, out CodeDiagnostic[] warnings, out CodeDiagnostic[] errors)
Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
Parameters:
| code (SyntaxTree) | Code to compile. |
| warnings (out CodeDiagnostic[]) | Code warnings, if any. |
| errors (out CodeDiagnostic[]) | Code errors, if any. |