Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Razor Compilation doesn't respect LangVersion property #1591

@tanaka-takayoshi

Description

@tanaka-takayoshi

Version: ASP.NET Core 2.0 Preview 2 with 2017 Preview (preview) (Version 15.3.0 Preview 6.0)
NuGet Version: Microsoft.AspNetCore.All 2.0.0-preview2-final

Though Razor has updated to support C# 7.1 in #1385, I failed to compile when I use C# 7.1 feature in Razor View Page.

@page
@model IndexModel
@{
    ViewData["Title"] = "Home Page";
    var x = 1;
    var y = 2;
    var t = (x, y);
    ViewData["X"] = t.x;
    ViewData["Y"] = t.y;
}

I suspect this is because explicit LangVersion in csproj is required to use C# 7.1 feature.

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <LangVersion>7.1</LangVersion>
  </PropertyGroup>

When I set LangVersion and write C# 7.1 feature in a normal csharp class, meaning not a Razor page, it can be compiled.

public static void Main(string[] args)
{
    var x = 1;
    var y = 2;
    var t = (x, y);
    Console.WriteLine(t.x);
    Console.WriteLine(t.y);
    BuildWebHost(args).Run();
}

Is there any workaround to respect LangVersion during razor compilation?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions