Parse LanguageVersion correctly

Fixes https://github.com/aspnet/Mvc/issues/6611
This commit is contained in:
Pranav K 2017-07-31 17:13:08 -07:00
parent fd9cb08790
commit 127d23a022
2 changed files with 11 additions and 5 deletions

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Hosting;
@ -154,11 +155,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
var parseOptions = new CSharpParseOptions(preprocessorSymbols: defines);
LanguageVersion languageVersion;
if (!string.IsNullOrEmpty(dependencyContextOptions.LanguageVersion) &&
Enum.TryParse(dependencyContextOptions.LanguageVersion, ignoreCase: true, result: out languageVersion))
if (!string.IsNullOrEmpty(dependencyContextOptions.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;

View File

@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
// Arrange
var dependencyContextOptions = new DependencyContextCompilationOptions(
new[] { "MyDefine" },
languageVersion: "CSharp7_1",
languageVersion: "7.1",
platform: null,
allowUnsafe: true,
warningsAsErrors: null,