|
27 | 27 | using System.Threading;
|
28 | 28 | using Microsoft.CodeAnalysis;
|
29 | 29 | using Microsoft.CodeAnalysis.CSharp;
|
| 30 | +using Microsoft.CodeAnalysis.Emit; |
30 | 31 |
|
31 | 32 | namespace Orts.Common.Scripting
|
32 | 33 | {
|
@@ -81,20 +82,34 @@ private static Assembly CompileScript(string[] path)
|
81 | 82 | {
|
82 | 83 | var scriptPath = path.Length > 1 ? Path.GetDirectoryName(path[0]) : path[0];
|
83 | 84 | var scriptName = Path.GetFileName(scriptPath);
|
| 85 | + var symbolsName = Path.ChangeExtension(scriptName, "pdb"); |
84 | 86 | try
|
85 | 87 | {
|
86 |
| - var syntaxTrees = path.Select(file => CSharpSyntaxTree.ParseText(File.ReadAllText(file), null, file)); |
| 88 | + var syntaxTrees = path.Select(file => CSharpSyntaxTree.ParseText(File.ReadAllText(file), null, file, Encoding.UTF8)); |
87 | 89 | var compilation = CSharpCompilation.Create(
|
88 | 90 | scriptName,
|
89 | 91 | syntaxTrees,
|
90 | 92 | References,
|
91 | 93 | CompilationOptions);
|
92 |
| - var ms = new MemoryStream(); |
93 |
| - var result = compilation.Emit(ms); |
| 94 | + |
| 95 | + var emitOptions = new EmitOptions( |
| 96 | + debugInformationFormat: DebugInformationFormat.PortablePdb, |
| 97 | + pdbFilePath: symbolsName); |
| 98 | + |
| 99 | + var assemblyStream = new MemoryStream(); |
| 100 | + var symbolsStream = new MemoryStream(); |
| 101 | + |
| 102 | + var result = compilation.Emit( |
| 103 | + assemblyStream, |
| 104 | + symbolsStream, |
| 105 | + options: emitOptions); |
| 106 | + |
94 | 107 | if (result.Success)
|
95 | 108 | {
|
96 |
| - ms.Seek(0, SeekOrigin.Begin); |
97 |
| - var script = Assembly.Load(ms.ToArray()); |
| 109 | + assemblyStream.Seek(0, SeekOrigin.Begin); |
| 110 | + symbolsStream.Seek(0, SeekOrigin.Begin); |
| 111 | + |
| 112 | + var script = Assembly.Load(assemblyStream.ToArray(), symbolsStream.ToArray()); |
98 | 113 | // in netcore:
|
99 | 114 | //var script = AssemblyLoadContext.Default.LoadFromStream(ms);
|
100 | 115 | if (script == null)
|
|
0 commit comments