Fix up error message when compilation references are missing
This commit is contained in:
parent
1aea6fd5bd
commit
a712ccc98a
|
|
@ -77,9 +77,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
string.Equals(CS0234, g.Id, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(CS0246, g.Id, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
additionalMessage = Resources.FormatCompilation_DependencyContextIsNotSpecified(
|
||||
"Microsoft.NET.Sdk.Web",
|
||||
"PreserveCompilationContext");
|
||||
additionalMessage = Resources.FormatCompilation_MissingReferences(
|
||||
"CopyRefAssembliesToPublishDirectory");
|
||||
}
|
||||
|
||||
var compilationFailure = new CompilationFailure(
|
||||
|
|
|
|||
|
|
@ -267,18 +267,18 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
=> string.Format(CultureInfo.CurrentCulture, GetString("LayoutHasCircularReference"), p0, p1);
|
||||
|
||||
/// <summary>
|
||||
/// One or more compilation references are missing. Ensure that your project is referencing '{0}' and the '{1}' property is not set to false.
|
||||
/// One or more compilation references may be missing. If you're seeing this in a published application, set '{0}' to true in your project file to ensure files in the refs directory are published.
|
||||
/// </summary>
|
||||
internal static string Compilation_DependencyContextIsNotSpecified
|
||||
internal static string Compilation_MissingReferences
|
||||
{
|
||||
get => GetString("Compilation_DependencyContextIsNotSpecified");
|
||||
get => GetString("Compilation_MissingReferences");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One or more compilation references are missing. Ensure that your project is referencing '{0}' and the '{1}' property is not set to false.
|
||||
/// One or more compilation references may be missing. If you're seeing this in a published application, set '{0}' to true in your project file to ensure files in the refs directory are published.
|
||||
/// </summary>
|
||||
internal static string FormatCompilation_DependencyContextIsNotSpecified(object p0, object p1)
|
||||
=> string.Format(CultureInfo.CurrentCulture, GetString("Compilation_DependencyContextIsNotSpecified"), p0, p1);
|
||||
internal static string FormatCompilation_MissingReferences(object p0)
|
||||
=> string.Format(CultureInfo.CurrentCulture, GetString("Compilation_MissingReferences"), p0);
|
||||
|
||||
/// <summary>
|
||||
/// '{0}' cannot be empty. These locations are required to locate a view for rendering.
|
||||
|
|
|
|||
|
|
@ -173,8 +173,8 @@
|
|||
<data name="LayoutHasCircularReference" xml:space="preserve">
|
||||
<value>A circular layout reference was detected when rendering '{0}'. The layout page '{1}' has already been rendered.</value>
|
||||
</data>
|
||||
<data name="Compilation_DependencyContextIsNotSpecified" xml:space="preserve">
|
||||
<value>One or more compilation references are missing. Ensure that your project is referencing '{0}' and the '{1}' property is not set to false.</value>
|
||||
<data name="Compilation_MissingReferences" xml:space="preserve">
|
||||
<value>One or more compilation references may be missing. If you're seeing this in a published application, set '{0}' to true in your project file to ensure files in the refs directory are published.</value>
|
||||
</data>
|
||||
<data name="ViewLocationFormatsIsRequired" xml:space="preserve">
|
||||
<value>'{0}' cannot be empty. These locations are required to locate a view for rendering.</value>
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
}
|
||||
}
|
||||
|
||||
throw new Exception($"Antiforgery token could not be located in {htmlDocument.TextContent}.");
|
||||
throw new Exception($"Antiforgery token could not be located in {htmlDocument.Source.Text}.");
|
||||
}
|
||||
|
||||
public static CookieMetadata RetrieveAntiforgeryCookie(HttpResponseMessage response)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using System.Net.Http;
|
|||
using System.Net.Http.Headers;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Razor.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||
|
|
@ -17,8 +16,8 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
public class ErrorPageTests : IClassFixture<MvcTestFixture<ErrorPageMiddlewareWebSite.Startup>>
|
||||
{
|
||||
private static readonly string PreserveCompilationContextMessage = HtmlEncoder.Default.Encode(
|
||||
"One or more compilation references are missing. Ensure that your project is referencing " +
|
||||
"'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false.");
|
||||
"One or more compilation references may be missing. " +
|
||||
"If you're seeing this in a published application, set 'CopyRefAssembliesToPublishDirectory' to true in your project file to ensure files in the refs directory are published.");
|
||||
public ErrorPageTests(MvcTestFixture<ErrorPageMiddlewareWebSite.Startup> fixture)
|
||||
{
|
||||
Client = fixture.CreateDefaultClient();
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Mvc.Razor.Extensions;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -43,6 +45,29 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
message.Message));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCompilationFailedResult_WithMissingReferences()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "One or more compilation references may be missing. If you're seeing this in a published application, set 'CopyRefAssembliesToPublishDirectory' to true in your project file to ensure files in the refs directory are published.";
|
||||
var compilation = CSharpCompilation.Create("Test", options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
var syntaxTree = CSharpSyntaxTree.ParseText("@class Test { public string Test { get; set; } }");
|
||||
compilation = compilation.AddSyntaxTrees(syntaxTree);
|
||||
var emitResult = compilation.Emit(new MemoryStream());
|
||||
|
||||
// Act
|
||||
var exception = CompilationFailedExceptionFactory.Create(
|
||||
RazorCodeDocument.Create(RazorSourceDocument.Create("Test", "Index.cshtml"), Enumerable.Empty<RazorSourceDocument>()),
|
||||
syntaxTree.ToString(),
|
||||
"Test",
|
||||
emitResult.Diagnostics);
|
||||
|
||||
// Assert
|
||||
Assert.Collection(
|
||||
exception.CompilationFailures,
|
||||
failure => Assert.Equal(expected, failure.FailureSummary));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCompilationFailedResult_UsesPhysicalPath()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue