Parse LanguageVersion correctly
Fixes https://github.com/aspnet/Razor/issues/1591
This commit is contained in:
parent
b3fe473e29
commit
eb5c23ea8e
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
|
@ -154,11 +155,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
|
|
||||||
var parseOptions = new CSharpParseOptions(preprocessorSymbols: defines);
|
var parseOptions = new CSharpParseOptions(preprocessorSymbols: defines);
|
||||||
|
|
||||||
LanguageVersion languageVersion;
|
if (!string.IsNullOrEmpty(dependencyContextOptions.LanguageVersion))
|
||||||
if (!string.IsNullOrEmpty(dependencyContextOptions.LanguageVersion) &&
|
|
||||||
Enum.TryParse(dependencyContextOptions.LanguageVersion, ignoreCase: true, result: out languageVersion))
|
|
||||||
{
|
{
|
||||||
parseOptions = parseOptions.WithLanguageVersion(languageVersion);
|
if (LanguageVersionFacts.TryParse(dependencyContextOptions.LanguageVersion, out var languageVersion))
|
||||||
|
{
|
||||||
|
parseOptions = parseOptions.WithLanguageVersion(languageVersion);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Fail($"LanguageVersion {languageVersion} specified in the deps file could not be parsed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseOptions;
|
return parseOptions;
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
// Arrange
|
// Arrange
|
||||||
var dependencyContextOptions = new DependencyContextCompilationOptions(
|
var dependencyContextOptions = new DependencyContextCompilationOptions(
|
||||||
new[] { "MyDefine" },
|
new[] { "MyDefine" },
|
||||||
languageVersion: "CSharp7_1",
|
languageVersion: "7.1",
|
||||||
platform: null,
|
platform: null,
|
||||||
allowUnsafe: true,
|
allowUnsafe: true,
|
||||||
warningsAsErrors: null,
|
warningsAsErrors: null,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue