Ensure PDB writer component is available before emiting PDB
Ported from
36cd4901f6
Fixes #1324
This commit is contained in:
parent
dd587f743b
commit
3f29de5a5f
|
|
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileSystems;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
|
|
@ -20,6 +21,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RoslynCompilationService : ICompilationService
|
public class RoslynCompilationService : ICompilationService
|
||||||
{
|
{
|
||||||
|
private readonly Lazy<bool> _supportsPdbGeneration = new Lazy<bool>(SupportsPdbGeneration);
|
||||||
private readonly ConcurrentDictionary<string, AssemblyMetadata> _metadataFileCache =
|
private readonly ConcurrentDictionary<string, AssemblyMetadata> _metadataFileCache =
|
||||||
new ConcurrentDictionary<string, AssemblyMetadata>(StringComparer.OrdinalIgnoreCase);
|
new ConcurrentDictionary<string, AssemblyMetadata>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
|
@ -70,13 +72,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
{
|
{
|
||||||
EmitResult result;
|
EmitResult result;
|
||||||
|
|
||||||
if (PlatformHelper.IsMono)
|
if (_supportsPdbGeneration.Value)
|
||||||
{
|
{
|
||||||
result = compilation.Emit(ms, pdbStream: null);
|
result = compilation.Emit(ms, pdbStream: pdb);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = compilation.Emit(ms, pdbStream: pdb);
|
result = compilation.Emit(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.Success)
|
if (!result.Success)
|
||||||
|
|
@ -94,15 +96,15 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
Assembly assembly;
|
Assembly assembly;
|
||||||
ms.Seek(0, SeekOrigin.Begin);
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
if (PlatformHelper.IsMono)
|
if (_supportsPdbGeneration.Value)
|
||||||
{
|
|
||||||
assembly = _loader.LoadStream(ms, pdbStream: null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
pdb.Seek(0, SeekOrigin.Begin);
|
pdb.Seek(0, SeekOrigin.Begin);
|
||||||
assembly = _loader.LoadStream(ms, pdb);
|
assembly = _loader.LoadStream(ms, pdb);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assembly = _loader.LoadStream(ms, pdbStream: null);
|
||||||
|
}
|
||||||
|
|
||||||
var type = assembly.GetExportedTypes()
|
var type = assembly.GetExportedTypes()
|
||||||
.First(t => t.Name.
|
.First(t => t.Name.
|
||||||
|
|
@ -187,5 +189,25 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
{
|
{
|
||||||
return diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error;
|
return diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool SupportsPdbGeneration()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (PlatformHelper.IsMono)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for the pdb writer component that roslyn uses to generate pdbs
|
||||||
|
const string SymWriterGuid = "0AE2DEB0-F901-478b-BB9F-881EE8066788";
|
||||||
|
|
||||||
|
return Marshal.GetTypeFromCLSID(new Guid(SymWriterGuid)) != null;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue