I'd like to be able to find out which C# version razor uses to compile my cshtml templates. The reason why I want this, is this breaking change.
We had a lambda in a foreach statement that worked fine on our local dev machines but produced a bug on our test environment (which doesn't have C# 5 installed). This bug was VERY hard to debug (we even copied all the test environment DLLs and databases and were still not able to reproduce the bug).
So to prevent this dev/test difference in the future I would like to know if there's a way to specify the C# version that razor should be using to compile cshtml files. It would also be nice if I could check the C# version that razor uses (by printing it).
Update: As requested, more details on how this behavior occurred.
We use a devexpress mvc grid to display data in our razor views. To add columns in a dynamic way we loop (foreach) a list which inserts columns in the datagrid (using a lambda). A simplified example:
@Html.DevExpress().GridView(
settings =>
{
settings.Name = "gvDashboard";
//Some more settings
settings.Columns.Add(column =>
{
column.FieldName = Model.DashboardItems.PropertyName(p => p.Id);
column.Caption = "Id";
//Some more column settings
});
foreach (var extraColumnLoopVar in Model.ExtraColumns)
{
//We added this to solve the problem
var extraColumn = extraColumnLoopVar;
settings.Columns.Add(column =>
{
column.Caption = extraColumn.Name;
//Some more column settings
column.SetDataItemTemplateContent(content =>
{
Html.ViewContext.Writer.Write(extraColumn.MyValue);
});
});
}
});