/// <summary> /// Emit the IL for the compilation into the specified stream. /// </summary> /// <param name="compilation">Compilation.</param> /// <param name="outputPath">Path of the file to which the PE image will be written.</param> /// <param name="pdbPath">Path of the file to which the compilation's debug info will be written. /// Also embedded in the output file. Null to forego PDB generation. /// </param> /// <param name="xmlDocumentationPath">Path of the file to which the compilation's XML documentation will be written. Null to forego XML generation.</param> /// <param name="win32ResourcesPath">Path of the file from which the compilation's Win32 resources will be read (in RES format). /// Null to indicate that there are none.</param> /// <param name="manifestResources">List of the compilation's managed resources. Null to indicate that there are none.</param> /// <param name="cancellationToken">To cancel the emit process.</param> /// <exception cref="ArgumentNullException">Compilation or path is null.</exception> /// <exception cref="ArgumentException">Path is empty or invalid.</exception> /// <exception cref="IOException">An error occurred while reading or writing a file.</exception> public static EmitResult Emit( this CSharpCompilation compilation, string outputPath, string pdbPath = null, string xmlDocumentationPath = null, string win32ResourcesPath = null, IEnumerable <ResourceDescription> manifestResources = null, CancellationToken cancellationToken = default(CancellationToken)) { return(FileSystemExtensions.Emit(compilation, outputPath, pdbPath, xmlDocumentationPath, win32ResourcesPath, manifestResources, cancellationToken)); }
private bool TryEmitAssembly(CSharpKernel kernel, string dstPath, out string assemblyPath) { Compilation compilation = kernel.ScriptState.Script.GetCompilation(); string assemblyName = AssemblyLoader.NormalizeAssemblyName(compilation.AssemblyName); assemblyPath = Path.Combine(dstPath, $"{assemblyName}.dll"); if (!File.Exists(assemblyPath)) { FileSystemExtensions.Emit(compilation, assemblyPath); return(true); } throw new Exception( $"TryEmitAssembly() unexpected duplicate assembly: ${assemblyPath}"); }