Use DebugType specified in DependencyContext to determine pdb type
Fixes #7006
This commit is contained in:
parent
276c1e4360
commit
51820e3e25
|
|
@ -21,19 +21,15 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
{
|
{
|
||||||
private readonly RazorReferenceManager _referenceManager;
|
private readonly RazorReferenceManager _referenceManager;
|
||||||
private readonly IHostingEnvironment _hostingEnvironment;
|
private readonly IHostingEnvironment _hostingEnvironment;
|
||||||
private readonly DebugInformationFormat _pdbFormat = SymbolsUtility.SupportsFullPdbGeneration() ?
|
|
||||||
DebugInformationFormat.Pdb :
|
|
||||||
DebugInformationFormat.PortablePdb;
|
|
||||||
private bool _optionsInitialized;
|
private bool _optionsInitialized;
|
||||||
private CSharpParseOptions _parseOptions;
|
private CSharpParseOptions _parseOptions;
|
||||||
private CSharpCompilationOptions _compilationOptions;
|
private CSharpCompilationOptions _compilationOptions;
|
||||||
|
private EmitOptions _emitOptions;
|
||||||
|
|
||||||
public CSharpCompiler(RazorReferenceManager manager, IHostingEnvironment hostingEnvironment)
|
public CSharpCompiler(RazorReferenceManager manager, IHostingEnvironment hostingEnvironment)
|
||||||
{
|
{
|
||||||
_referenceManager = manager ?? throw new ArgumentNullException(nameof(manager));
|
_referenceManager = manager ?? throw new ArgumentNullException(nameof(manager));
|
||||||
_hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
|
_hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
|
||||||
|
|
||||||
EmitOptions = new EmitOptions(debugInformationFormat: _pdbFormat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual CSharpParseOptions ParseOptions
|
public virtual CSharpParseOptions ParseOptions
|
||||||
|
|
@ -54,7 +50,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EmitOptions EmitOptions { get; }
|
public virtual EmitOptions EmitOptions
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
EnsureOptions();
|
||||||
|
return _emitOptions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SyntaxTree CreateSyntaxTree(SourceText sourceText)
|
public SyntaxTree CreateSyntaxTree(SourceText sourceText)
|
||||||
{
|
{
|
||||||
|
|
@ -94,11 +97,47 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
var dependencyContextOptions = GetDependencyContextCompilationOptions();
|
var dependencyContextOptions = GetDependencyContextCompilationOptions();
|
||||||
_parseOptions = GetParseOptions(_hostingEnvironment, dependencyContextOptions);
|
_parseOptions = GetParseOptions(_hostingEnvironment, dependencyContextOptions);
|
||||||
_compilationOptions = GetCompilationOptions(_hostingEnvironment, dependencyContextOptions);
|
_compilationOptions = GetCompilationOptions(_hostingEnvironment, dependencyContextOptions);
|
||||||
|
_emitOptions = GetEmitOptions(dependencyContextOptions);
|
||||||
|
|
||||||
_optionsInitialized = true;
|
_optionsInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EmitOptions GetEmitOptions(DependencyContextCompilationOptions dependencyContextOptions)
|
||||||
|
{
|
||||||
|
DebugInformationFormat debugInformationFormat;
|
||||||
|
if (string.IsNullOrEmpty(dependencyContextOptions.DebugType))
|
||||||
|
{
|
||||||
|
debugInformationFormat = SymbolsUtility.SupportsFullPdbGeneration() ?
|
||||||
|
DebugInformationFormat.Pdb :
|
||||||
|
DebugInformationFormat.PortablePdb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Based on https://github.com/dotnet/roslyn/blob/1d28ff9ba248b332de3c84d23194a1d7bde07e4d/src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs#L624-L640
|
||||||
|
switch (dependencyContextOptions.DebugType.ToLower())
|
||||||
|
{
|
||||||
|
case "portable":
|
||||||
|
debugInformationFormat = DebugInformationFormat.PortablePdb;
|
||||||
|
break;
|
||||||
|
case "embedded":
|
||||||
|
debugInformationFormat = DebugInformationFormat.Embedded;
|
||||||
|
break;
|
||||||
|
case "full":
|
||||||
|
case "pdbonly":
|
||||||
|
debugInformationFormat = SymbolsUtility.SupportsFullPdbGeneration() ?
|
||||||
|
DebugInformationFormat.Pdb :
|
||||||
|
DebugInformationFormat.PortablePdb;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException(Resources.FormatUnsupportedDebugInformationFormat(dependencyContextOptions.DebugType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var emitOptions = new EmitOptions(debugInformationFormat: debugInformationFormat);
|
||||||
|
return emitOptions;
|
||||||
|
}
|
||||||
|
|
||||||
private static CSharpCompilationOptions GetCompilationOptions(
|
private static CSharpCompilationOptions GetCompilationOptions(
|
||||||
IHostingEnvironment hostingEnvironment,
|
IHostingEnvironment hostingEnvironment,
|
||||||
DependencyContextCompilationOptions dependencyContextOptions)
|
DependencyContextCompilationOptions dependencyContextOptions)
|
||||||
|
|
|
||||||
|
|
@ -364,6 +364,20 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
||||||
internal static string FormatRazorViewCompiler_ViewPathsDifferOnlyInCase()
|
internal static string FormatRazorViewCompiler_ViewPathsDifferOnlyInCase()
|
||||||
=> GetString("RazorViewCompiler_ViewPathsDifferOnlyInCase");
|
=> GetString("RazorViewCompiler_ViewPathsDifferOnlyInCase");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The debug type specified in the dependency context could be parsed. The debug type value '{0}' is not supported.
|
||||||
|
/// </summary>
|
||||||
|
internal static string UnsupportedDebugInformationFormat
|
||||||
|
{
|
||||||
|
get => GetString("UnsupportedDebugInformationFormat");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The debug type specified in the dependency context could be parsed. The debug type value '{0}' is not supported.
|
||||||
|
/// </summary>
|
||||||
|
internal static string FormatUnsupportedDebugInformationFormat(object p0)
|
||||||
|
=> string.Format(CultureInfo.CurrentCulture, GetString("UnsupportedDebugInformationFormat"), p0);
|
||||||
|
|
||||||
private static string GetString(string name, params string[] formatterNames)
|
private static string GetString(string name, params string[] formatterNames)
|
||||||
{
|
{
|
||||||
var value = _resourceManager.GetString(name);
|
var value = _resourceManager.GetString(name);
|
||||||
|
|
|
||||||
|
|
@ -194,4 +194,7 @@
|
||||||
<data name="RazorViewCompiler_ViewPathsDifferOnlyInCase" xml:space="preserve">
|
<data name="RazorViewCompiler_ViewPathsDifferOnlyInCase" xml:space="preserve">
|
||||||
<value>The following precompiled view paths differ only in case, which is not supported:</value>
|
<value>The following precompiled view paths differ only in case, which is not supported:</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="UnsupportedDebugInformationFormat" xml:space="preserve">
|
||||||
|
<value>The debug type specified in the dependency context could be parsed. The debug type value '{0}' is not supported.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
|
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
|
using Microsoft.CodeAnalysis.Emit;
|
||||||
using Microsoft.CodeAnalysis.Text;
|
using Microsoft.CodeAnalysis.Text;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -172,6 +173,36 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
Assert.Equal(LanguageVersion.CSharp7_1, compilationOptions.LanguageVersion);
|
Assert.Equal(LanguageVersion.CSharp7_1, compilationOptions.LanguageVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("portable", DebugInformationFormat.PortablePdb)]
|
||||||
|
[InlineData("embedded", DebugInformationFormat.Embedded)]
|
||||||
|
public void EmitOptions_ReadsDebugTypeFromDependencyContext(string debugType, DebugInformationFormat expected)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var dependencyContextOptions = new DependencyContextCompilationOptions(
|
||||||
|
new[] { "MyDefine" },
|
||||||
|
languageVersion: "7.1",
|
||||||
|
platform: null,
|
||||||
|
allowUnsafe: true,
|
||||||
|
warningsAsErrors: null,
|
||||||
|
optimize: null,
|
||||||
|
keyFile: null,
|
||||||
|
delaySign: null,
|
||||||
|
publicSign: null,
|
||||||
|
debugType: debugType,
|
||||||
|
emitEntryPoint: null,
|
||||||
|
generateXmlDocumentation: null);
|
||||||
|
var referenceManager = Mock.Of<RazorReferenceManager>();
|
||||||
|
var hostingEnvironment = Mock.Of<IHostingEnvironment>();
|
||||||
|
|
||||||
|
var compiler = new TestCSharpCompiler(referenceManager, hostingEnvironment, dependencyContextOptions);
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
var emitOptions = compiler.EmitOptions;
|
||||||
|
Assert.Equal(expected, emitOptions.DebugInformationFormat);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Constructor_ConfiguresAllowUnsafe()
|
public void Constructor_ConfiguresAllowUnsafe()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue