Merge remote-tracking branch 'origin/v12/dev' into v13/dev

This commit is contained in:
Bjarke Berg
2023-01-24 12:04:01 +01:00
5 changed files with 53 additions and 44 deletions

View File

@@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Reflection;
using System.Text;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
using Microsoft.AspNetCore.Razor.Hosting;
using Microsoft.AspNetCore.Razor.Language;
@@ -13,6 +14,7 @@ using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Umbraco.Extensions;
namespace Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto;
@@ -375,13 +377,17 @@ internal class CollectibleRuntimeViewCompiler : IViewCompiler
pdbStream,
options: _compilationOptionsProvider.EmitOptions);
if (!result.Success)
if (result.Success is false)
{
throw CompilationExceptionFactory.Create(
UmbracoCompilationException compilationException = CompilationExceptionFactory.Create(
codeDocument,
generatedCode,
assemblyName,
result.Diagnostics);
LogCompilationFailure(compilationException);
throw compilationException;
}
assemblyStream.Seek(0, SeekOrigin.Begin);
@@ -393,6 +399,21 @@ internal class CollectibleRuntimeViewCompiler : IViewCompiler
}
}
private void LogCompilationFailure(UmbracoCompilationException compilationException)
{
IEnumerable<string>? messages = compilationException.CompilationFailures?
.WhereNotNull()
.SelectMany(x => x.Messages!)
.WhereNotNull()
.Select(x => x.FormattedMessage)
.WhereNotNull();
foreach (var message in messages ?? Enumerable.Empty<string>())
{
_logger.LogError(compilationException, "Compilation error occured with message: {ErrorMessage}", message);
}
}
private CSharpCompilation CreateCompilation(string compilationContent, string assemblyName)
{
IReadOnlyList<MetadataReference> refs = _referenceManager.CompilationReferences;