Skip to content

Commit c1d5010

Browse files
committed
Add mdb support to roslyn
1 parent 84bde54 commit c1d5010

19 files changed

+3345
-6
lines changed

IncrementalCompiler.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompilerPlugin.Unity5", "ex
1515
EndProject
1616
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalCompiler", "extra\UniversalCompiler\UniversalCompiler.csproj", "{B19F1DAC-FA9A-4749-9E03-1848D29BFCCD}"
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoslynMdbWriter", "core\RoslynMdbWriter\RoslynMdbWriter.csproj", "{286226F3-564D-480A-B6C2-2D207CBFB064}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|Any CPU = Debug|Any CPU
@@ -37,6 +39,10 @@ Global
3739
{B19F1DAC-FA9A-4749-9E03-1848D29BFCCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
3840
{B19F1DAC-FA9A-4749-9E03-1848D29BFCCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
3941
{B19F1DAC-FA9A-4749-9E03-1848D29BFCCD}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{286226F3-564D-480A-B6C2-2D207CBFB064}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43+
{286226F3-564D-480A-B6C2-2D207CBFB064}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{286226F3-564D-480A-B6C2-2D207CBFB064}.Release|Any CPU.ActiveCfg = Release|Any CPU
45+
{286226F3-564D-480A-B6C2-2D207CBFB064}.Release|Any CPU.Build.0 = Release|Any CPU
4046
EndGlobalSection
4147
GlobalSection(SolutionProperties) = preSolution
4248
HideSolutionNode = FALSE
@@ -46,5 +52,6 @@ Global
4652
{A848498C-64E7-444F-83FD-FCFE42E79E53} = {A22672B3-D1C4-47C0-AB82-6D22BBB94BBB}
4753
{67FE81D8-C1BF-4D15-A512-E9E8078DEECF} = {A22672B3-D1C4-47C0-AB82-6D22BBB94BBB}
4854
{B19F1DAC-FA9A-4749-9E03-1848D29BFCCD} = {A22672B3-D1C4-47C0-AB82-6D22BBB94BBB}
55+
{286226F3-564D-480A-B6C2-2D207CBFB064} = {092669A2-567F-4C73-A01E-AEBA2C733994}
4956
EndGlobalSection
5057
EndGlobal

core/IncrementalCompiler/Compiler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.CodeAnalysis.CSharp;
66
using System.Linq;
77
using System.Text;
8+
using Mono.CompilerServices.SymbolWriter;
89
using NLog;
910

1011
namespace IncrementalCompiler
@@ -145,11 +146,11 @@ private SyntaxTree ParseSource(string file, CSharpParseOptions parseOption)
145146
private void Emit(CompileResult result)
146147
{
147148
var outputFile = Path.Combine(_options.WorkDirectory, _options.Output);
148-
var debugFile = Path.Combine(_options.WorkDirectory, Path.ChangeExtension(_options.Output, ".pdb"));
149+
var debugFile = Path.Combine(_options.WorkDirectory, _options.Output + ".mdb");
149150
using (var peStream = new FileStream(outputFile, FileMode.Create))
150151
using (var pdbStream = new FileStream(debugFile, FileMode.Create))
151152
{
152-
var r = _compilation.Emit(peStream, pdbStream);
153+
var r = _compilation.EmitWithMdb(peStream, pdbStream);
153154

154155
foreach (var d in r.Diagnostics)
155156
{

core/IncrementalCompiler/IncrementalCompiler.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@
8383
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
8484
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
8585
</ItemGroup>
86+
<ItemGroup>
87+
<ProjectReference Include="..\RoslynMdbWriter\RoslynMdbWriter.csproj">
88+
<Project>{286226f3-564d-480a-b6c2-2d207cbfb064}</Project>
89+
<Name>RoslynMdbWriter</Name>
90+
</ProjectReference>
91+
</ItemGroup>
8692
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8793
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8894
Other similar extension points exist, see Microsoft.Common.targets.

core/RoslynMdbWriter/MdbHelper.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading;
5+
using Microsoft.CodeAnalysis.Emit;
6+
using Microsoft.CodeAnalysis;
7+
using Microsoft.CodeAnalysis.CodeGen;
8+
9+
namespace Mono.CompilerServices.SymbolWriter
10+
{
11+
public static class MdbHelper
12+
{
13+
public static EmitResult EmitWithMdb(this Compilation compilation, Stream peStream, Stream pdbStream = null,
14+
Stream xmlDocumentationStream = null, Stream win32Resources = null,
15+
IEnumerable<ResourceDescription> manifestResources = null, EmitOptions options = null,
16+
IMethodSymbol debugEntryPoint = null, CancellationToken cancellationToken = default(CancellationToken))
17+
{
18+
if (peStream == null)
19+
{
20+
throw new ArgumentNullException(nameof(peStream));
21+
}
22+
23+
if (!peStream.CanWrite)
24+
{
25+
throw new ArgumentException(CodeAnalysisResources.StreamMustSupportWrite, nameof(peStream));
26+
}
27+
28+
if (pdbStream != null && !pdbStream.CanWrite)
29+
{
30+
throw new ArgumentException(CodeAnalysisResources.StreamMustSupportWrite, nameof(pdbStream));
31+
}
32+
33+
var testData = new CompilationTestData
34+
{
35+
SymWriterFactory = () => new MdbWriter()
36+
};
37+
38+
return compilation.Emit(
39+
peStream,
40+
pdbStream,
41+
xmlDocumentationStream,
42+
win32Resources,
43+
manifestResources,
44+
options,
45+
debugEntryPoint,
46+
testData,
47+
null,
48+
cancellationToken);
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)