modelsbuilder / ModelsBuilder.Original

The Community Models Builder for Umbraco
MIT License
114 stars 49 forks source link

C#6 expression-bodied members not supported in extension classes for models #126

Closed mzajkowski closed 7 years ago

mzajkowski commented 7 years ago

Steps to reproduce the problem:

  1. Setup the simple solution on Umbraco 7.5.x (I presume that it affects all versions where usage of ModelsBuilder is possible).
  2. Set up AppData / LiveAppData ModelsMode.
  3. Generate models and include them in solution in VS.
  4. Create additional .cs file for extending generated model for one of the document types.
  5. Create property in newly created class with usage of new C#6 expression-bodied functionality.
  6. Try to regenerate models from Umbraco backoffice.

Result of above steps:

Failed to build models. Feature 'expression-bodied property' is not available in C# 5. Please use language version 6 or greater.

at Umbraco.ModelsBuilder.Building.Compiler.ThrowExceptionFromDiagnostic(String path, String code, Diagnostic diagnostic) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 161 at Umbraco.ModelsBuilder.Building.Compiler.<>c__DisplayClass12_0.b__0(KeyValuePair2 x) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 50 at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Umbraco.ModelsBuilder.Building.Compiler.GetCompilation(String assemblyName, IDictionary2 files, SyntaxTree[]& trees) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 46 at Umbraco.ModelsBuilder.Building.CodeParser.Parse(IDictionary2 files, IEnumerable1 references) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\CodeParser.cs:line 38 at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.GenerateModels(String modelsDirectory, String bin) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 108 at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.BuildModels() in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 35

Tried workarounds / fixes:

  1. Installed Microsoft.Net.Compilers NuGet package.
  2. Enabling C# 6 support for the project.
zpqrtbnk commented 7 years ago

Can you try setting the Umbraco.ModelsBuilder.LanguageVersion appSetting to "CSharp6" as per https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Install-And-Configure? IIRC by default we only support C# 5.

mzajkowski commented 7 years ago

Arghhh, sure. Missed it. It works. Thanks @zpqrtbnk!