Repository: dotnet/roslyn
File: src/Compilers/Test/Core/CompilationVerifier.cs (C#)

Code before:
                        rebuildData: null,
                        testData: testData,
                        cancellationToken: default);
                }
                finally
                {
                    if (pdbStream != null)
                    {
                        pdb = getBytes(pdbStream);
                        pdbStream.Dispose();
                    }
                }

                diagnostics.AddRange(result.Diagnostics);
                assembly = getBytes(executableStream);

                if (result.Success)
                {
                    return new EmitOutput(assembly, pdb);
                }

                return null;

                Stream getStream(string? assemblyName, string ext)
                {
                    if (Environment.GetEnvironmentVariable("ROSLYN_TEST_EMIT_PATH") is string { Length: > 0 } basePath)
                    {
                        if (!Directory.Exists(basePath))
                        {
                            throw new InvalidOperationException($"The test emit directory '{basePath}' does not exist.");
                        }

                        var path = Path.Combine(basePath, $"{assemblyName ?? Guid.NewGuid().ToString()}.{ext}");
                        if (File.Exists(path))
                        {
                            path = Path.Combine(basePath, $"{assemblyName}{Guid.NewGuid()}.{ext}");
                        }

                        return new FileStream(path, FileMode.CreateNew);
                    }

                    return new MemoryStream();
                }

                ImmutableArray<byte> getBytes(Stream stream)
                {
                    if (stream is MemoryStream ms)
                    {
                        return ms.ToImmutable();
                    }


Review comment (suggestion):
We already have a machinery to dump DLLs:

https://github.com/dotnet/roslyn/blob/4f9e5aef45e3d5255e8fcb1bf8c30020a19425af/src/Compilers/Test/Core/CompilationVerifier.cs#L40

https://github.com/dotnet/roslyn/blob/4f9e5aef45e3d5255e8fcb1bf8c30020a19425af/src/Compilers/Test/Core/CompilationVerifier.cs#L171

Should we reuse it?

I also feel like setting an env var would be difficult when running the test in VS, for example. Perhaps uncommenting an `#if` symbol would be a nice alternative.

Code after:
                        options: emitOptions,
                        debugEntryPoint: null,
                        sourceLinkStream: null,
                        embeddedTexts,
                        rebuildData: null,
                        testData: testData,
                        cancellationToken: default);
                }
                finally
                {
                    if (pdbStream != null)
                    {
                        pdb = pdbStream.ToImmutable();
                        pdbStream.Dispose();
                    }
                }

                diagnostics.AddRange(result.Diagnostics);
                assembly = executableStream.ToImmutable();

                if (result.Success)
                {
                    return new EmitOutput(assembly, pdb);
                }

                return null;
            }
        }
    }
}